收到错误 收到类型 'mytasks.add' 的未注册任务



我已经编写了一个文件mytasks.py

from celery import Celery
celery = Celery("tasks",
                broker='redis://localhost:6379/0',
                backend='redis')

@celery.task
def add(x,y):
        return x+y

CCD_ 2如下

from mytasks import add
add.delay(1,1)

我已经启动了redis服务器,并且已经启动了芹菜服务器。但是当我运行task.py时,我会得到以下错误:

    Received unregistered task of type 'mytasks.add'.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.
The full contents of the message body was:
{'retries': 0, 'task': 'mytasks.add', 'eta': None, 'args': (1, 1), 'expires': None, 'callbacks': None, 'errbacks': None, 'kwargs': {}, 'id': 'a4792308-d575-4de4-8b67-26982cae2fa4', 'utc': True} (173b)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py", line 411, in on_task_received
    strategies[name](message, body, message.ack_log_error)
KeyError: 'mytasks.add'

的可能原因是什么

嘿,我已经解决了这个问题我做了一件事,我添加了

CELERY_IMPORTS=("mytasks")

在我的celeryconfig.py文件中,我成功了。

也可以在Celery类中使用include参数:http://docs.celeryproject.org/en/latest/getting-started/next-steps.html#proj-芹菜py

相关内容

  • 没有找到相关文章

最新更新