如何安排任务在特定时间使用芹菜进行? [英] How can I schedule a Task to execute at a specific time using celery?
本文介绍了如何安排任务在特定时间使用芹菜进行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经研究了 PeriodicTask
,但是这些例子只包括使其重复出现。我正在寻找一些更像codecron 的能力,说每个星期一凌晨1点执行这个任务的一些东西。
I've looked into PeriodicTask
, but the examples only cover making it recur. I'm looking for something more like cron
's ability to say "execute this task every Monday at 1 a.m."
推荐答案
最近发布的版本1.0.3现在支持这一点,谢谢Patrick Altman!
The recently released version 1.0.3 supports this now, thanks to Patrick Altman!
示例:
from celery.task.schedules import crontab
from celery.decorators import periodic_task
@periodic_task(run_every=crontab(hour=7, minute=30, day_of_week="mon"))
def every_monday_morning():
print("This runs every Monday morning at 7:30a.m.")
有关更多信息,请参阅更改日志:
See the changelog for more information:
http://celeryproject.org/docs/changelog.html
这篇关于如何安排任务在特定时间使用芹菜进行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文