Can celery's beat tasks execute at timed intervals?

让人想犯罪 __ 提交于 2019-12-10 12:16:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!