Answer the question
In order to leave comments, you need to log in
How to set periodic tasks in Celery declaratively with a dictionary in app.conf = {...}?
It works:
# 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,
celery -A tasks beat -s ./celerybeat-schedule # планировщик
celery -A tasks worker # воркер
Answer the question
In order to leave comments, you need to log in
Because it needs to be like this:
# 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': 'tasks.show', # instead 'show'
'schedule': 5.0,
'args': (42,),
},
}
app.conf.timezone = 'UTC'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question