我读过不少类似的帖子,但似乎没有一篇对我有意义。
我正在尝试配置芹菜周期,要求每5秒触发一次,但我被芹菜配置问题挂断了(我想)
通信/任务.py
import datetime
from celery.decorators import periodic_task
@periodic_task
def send_queued_messages():
# do something...
myapp/settings.py
...
from comm.tasks import send_queued_messages
from datetime import timedelta
CELERYBEAT_SCHEDULE = {
'send_queued_messages_every_5_seconds': {
'task': 'comm.tasks.send_queued_messages', # Is the issue here? I've tried a dozen variations!!
'schedule': timedelta(seconds=5),
},
}
我的错误日志的相关输出:
23:41:00 worker.1 | [2015-06-10 03:41:00,657: ERROR/MainProcess] Received unregistered task of type 'send_queued_messages'.
23:41:00 worker.1 | The message has been ignored and discarded.
23:41:00 worker.1 |
23:41:00 worker.1 | Did you remember to import the module containing this task?
23:41:00 worker.1 | Or maybe you are using relative imports?
23:41:00 worker.1 | Please see http://bit.ly/gLye1c for more information.
23:41:00 worker.1 |
23:41:00 worker.1 | The full contents of the message body was:
23:41:00 worker.1 | {'utc': True, 'chord': None, 'args': [], 'retries': 0, 'expires': None, 'task': 'send_queued_messages', 'callbacks': None, 'errbacks': None, 'timelimit': (None, None), 'taskset': None, 'kwargs': {}, 'eta': None, 'id': 'a8ca18...227a56'} (216b)
如果在celery document后面的
proj/proj/celery.py
中使用下面的代码而且它看起来和教程不一样
别忘了把你的新应用添加到
INSTALLED_APPS
中settings.py
我遇到了这个确切的问题,结果发现问题不在任务的名称上,而是芹菜工人不知道您的任务模块。
换句话说,您的任务名是正确的(
'comm.tasks.send_queued_messages'
),它是由任务装饰器生成的,您只是没有告诉芹菜在哪里查找它。最快的解决方案是将以下内容添加到
myapp/settings.py
:根据the docs,这决定了“工作进程启动时要导入的模块序列”
或者,您可以将设置配置为自动发现任务(see docs here),但随后必须命名任务模块,将
comm/tasks.py
移动到comm/comm/tasks.py
。对我来说,混淆来自于芹菜的自动命名约定,它看起来像一个import语句,这让我相信我是在用
CELERYBEAT_SCHEDULE['task']
告诉芹菜在哪里寻找任务。相反,调度程序只是将名称作为字符串。有关任务命名的解释,请参见the celery docs。
在这种情况下,您需要向celerybeat提供它可以找到的任务名称。
试试这个:
相关问题 更多 >
编程相关推荐