Это работает:
# tasks.py:
import celery
app = celery.Celery('tasks', broker='redis://127.0.0.1:6379')
@app.task
def show(arg):
print(arg)
app.add_periodic_task(5, show.s(42), name='task-name')
А это не работает:
# tasks.py:
import celery
app = celery.Celery('tasks', broker='redis://127.0.0.1:6379')
@app.task
def show(arg):
print(arg)
app.conf.beat_schedule = {
'task-name': {
'task': 'show',
'schedule': 5.0,
'args': (42,),
},
}
app.conf.timezone = 'UTC'
Воркер падает с ошибкой:
[2019-08-26 18:09:16,333: ERROR/MainProcess] Received unregistered task of type 'show'.
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
docs.celeryq.org/en/latest/internals/protocol.html
for more information.
The full contents of the message body was:
b'[[42], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]' (79b)
Traceback (most recent call last):
File "/home/oleg/projects/asm/.venv/lib/python3.6/site-packages/celery/worker/consumer/consumer.py", line 558, in on_task_received
strategy = strategies[type_]
KeyError: 'show'
Запускаю так:
celery -A tasks beat -s ./celerybeat-schedule # планировщик
celery -A tasks worker # воркер
Но я хочу задавать таски вторым способом.
Что не так?