收到错误接收到未注册的'mytasks.add'类型的任务 [英] getting error Received unregistered task of type 'mytasks.add'

查看:25
本文介绍了收到错误接收到未注册的'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

task.py 如下

from mytasks import add

add.delay(1,1)

我已经启动了Redis服务器,也已经启动了celery服务器.但是当我运行task.py时,出现以下错误:

I have started redis server and I have started celery server. but when i m running task.py then i am getting the following error:

    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'

可能是什么原因

推荐答案

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

Hey I have solved the problem i did one thing i add

CELERY_IMPORTS=("mytasks")

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

in my celeryconfig.py file and i got succeed.

这篇关于收到错误接收到未注册的'mytasks.add'类型的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆