芹菜周期性任务没有在Djang运行

2024-06-26 14:13:11 发布

您现在位置:Python中文网/ 问答频道 /正文

文件结构

proj/proj/
         celery.py
         (and other files)
    /sitesettings/
         tasks.py
         (and other files)

在芹菜.py在

^{pr2}$

站点设置/任务.py在

from __future__ import absolute_import, unicode_literals
from comma.models import Post
from mooncake.celery import app

app.conf.beat_schedule = {
'every-5-seconds': {
    'task': 'sitesettings.tasks.statisticsTag',
    'schedule': 5.0,
    'args': ()
},
}

@app.task
def statisticsTag():
    print(Post.objects.all()[0])

然后用

celery -A proj beat -l info

把它弄出来

[2019-02-22 18:21:08,346: INFO/MainProcess] Scheduler: Sending due task every-5-seconds (sitesettings.tasks.statisticsTag)

但没有更多的产出。 我曾经试着用proj写/芹菜.py但它不能运行,因为我必须从另一个应用程序导入,它退出时出现“app not loaded”错误。那我该怎么办?在


Tags: andfrompyimportapptaskfilespost
1条回答
网友
1楼 · 发布于 2024-06-26 14:13:11

您正在调用的启动celerycelery -A proj beat -l info的命令是celery的starting a beat scheduler instance,它将到期的任务发送给一个worker实例。在

您还需要start a worker server来执行那些到期的任务。您可以使用命令celery -A proj worker -l info启动一个芹菜工人。这将需要在运行调度程序的同时运行。在

或者,您可以运行worker with embedded beat schedulercelery -A proj woker -B -l info,但不建议在生产中使用。在

相关问题 更多 >