当我尝试运行此代码时,它将引发错误, 我想将task_number_one和print_test作为定期任务运行,但对两者都引发相同的错误。
from celery.task import periodic_task
from celery.schedules import crontab
from celery import task
@task()
def task_number_one():
print("Celery Task Working...")
@periodic_task(run_every=crontab(minute='10', hour='6,8,9,10,11,12'))
def print_test():
print(1)
task_number_one.delay()
我得到以下错误
[2019-09-18 17:21:17,093: ERROR/MainProcess] Received unregistered task of type 'page.tasks.task_number_one'.
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:
'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]' (77b)
Traceback (most recent call last):
File "/home/naanal/venv/lib/python3.6/site-packages/celery/worker/consumer/consumer.py", line 559, in on_task_received
strategy = strategies[type_]
KeyError: 'page.tasks.task_number_one'
答案 0 :(得分:0)
如果您使用的是celery v4,则注册任务的方式与使用v3进行注册的方式不同。对于v4,请使用以下命令:
from myapp.celery import app
@app.task
def task_number_one():
print("Celery Task Working...")