芹菜的节拍任务可以按时间间隔执行吗? [英] Can celery's beat tasks execute at timed intervals?

查看:40
本文介绍了芹菜的节拍任务可以按时间间隔执行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是节拍任务设置:

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),
},
})

通常,taskA,taskB,taskC在我的命令 celery -A myproj beat 作为节拍任务后同时执行.但是现在我希望任务A先执行,然后一段时间再执行任务B,然后任务C最后执行.在3600秒之后,他们再次执行.在3600秒之后,他们再次执行.在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?

推荐答案

是的,有可能.为所有三个任务创建一个链,然后使用此链式任务进行调度.

Yeah, it's possible. Create a chain for all three tasks and then use this chained task for scheduling.

在您的 tasks.py 文件中:

from celery import chain
chained_task = chain(taskA, taskB, taskC)

然后安排 chained_task :

celery_app.conf.update(
CELERYBEAT_SCHEDULE = {
'chained_task': {
    'task': 'crawlerapp.tasks.manual_crawler_update',
    'schedule': timedelta(seconds=3600),
},  
})

这样,您的任务将在3600秒内按顺序执行一次.

By this, your task will execute in order once in 3600 seconds.

这篇关于芹菜的节拍任务可以按时间间隔执行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆