问题
This is the beat tasks setting:
celery_app.conf.update(
CELERYBEAT_SCHEDULE = {
'taskA': {
'task': 'crawlerapp.tasks.manual_crawler_update',
'schedule': timedelta(seconds=3600),
},
'taskB': {
'task': 'crawlerapp.tasks.auto_crawler_update_day',
'schedule': timedelta(seconds=3600),
},
'taskC': {
'task': 'crawlerapp.tasks.auto_crawler_update_hour',
'schedule': timedelta(seconds=3600),
},
})
Normally taskA,taskB,taskC execute at the same time after my command celery -A myproj beat
as the beat tasks. But now I want that taskA execute first,and then some time later taskB excute second,taskC excute at last.And after 3600 seconds they excute again.And after 3600 seconds they excute again.And after 3600 seconds they excute again. Is it possible?
回答1:
Yeah, it's possible. Create a chain for all three tasks and then use this chained task for scheduling.
In your tasks.py
file:
from celery import chain
chained_task = chain(taskA, taskB, taskC)
Then schedule the chained_task
:
celery_app.conf.update(
CELERYBEAT_SCHEDULE = {
'chained_task': {
'task': 'crawlerapp.tasks.manual_crawler_update',
'schedule': timedelta(seconds=3600),
},
})
By this, your task will execute in order once in 3600 seconds.
来源:https://stackoverflow.com/questions/25955798/can-celerys-beat-tasks-execute-at-timed-intervals