tasks.py
from celery import Task
class SimpleTask(Task):
def run(self):
print("run")
执行python manage.py shell
In [3]: from products.tasks import SimpleTask
In [4]: task = SimpleTask()
In [6]: task.run()
run
成功工作,工作服务器中没有错误日志。
Howerver,
In [7]: task.delay()
Out[7]: <AsyncResult: a2e90b17-2af9-49b4-82df-562955beaf69>
工作服务器日志显示错误:
[2016-11-05 18:44:03,171: ERROR/MainProcess] Received unregistered task of type None.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you're using relative imports?
Please see
http://docs.celeryq.org/en/latest/internals/protocol.html
for more information.
The full contents of the message body was:
b'[[], {}, {"callbacks": null, "chord": null, "errbacks": null, "chain": null}]' (77b)
Traceback (most recent call last):
File "/Users/Chois/.pyenv/versions/3.5.1/envs/spacegraphy/lib/python3.5/site-packages/celery/worker/consumer/consumer.py", line 549, in on_task_received
strategy = strategies[type_]
KeyError
我不明白为什么会这样。如果我使用@shared_task
创建基于功能的任务,它就能成功运行。但只有基于班级的Task
无效。
需要帮助,谢谢。
答案 0 :(得分:0)
基于类的任务我遇到了同样的问题,但是在Django中却没有。通过在任务上设置(Unsigned) 12345.67 >> 3456700F
属性来解决此问题。
name