我如何安排任务在特定的时间执行芹菜?

时间:2023-02-09 01:21:36

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."

我已经研究过PeriodicTask,但是这个例子只涉及到如何重复循环。我正在寻找一种更像cron所说的“每周一凌晨1点执行这个任务”的能力。

5 个解决方案

#1


27  

The recently released version 1.0.3 supports this now, thanks to Patrick Altman!

最近发布的1.0.3版本现在支持这个功能,这要感谢Patrick Altman!

Example:

例子:

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:

更多信息请参见changelog:

http://celeryproject.org/docs/changelog.html

http://celeryproject.org/docs/changelog.html

#2


26  

Use

使用

YourTask.apply_async(args=[some, args, here], eta=when)

And at the end of your task, reschedule it to the next time it should run.

在你的任务结束时,将它重新安排到下一次应该运行的时间。

#3


5  

I have just submitted a patch to add a ScheduledTask to accomplish a small bit of time based scheduling versus period based:

我刚刚提交了一个补丁,添加了一个ScheduledTask来完成一小部分基于时间的调度,而不是基于时间的:

https://github.com/celery/celery/commit/e8835f1052bb45a73f9404005c666f2d2b9a9228

https://github.com/celery/celery/commit/e8835f1052bb45a73f9404005c666f2d2b9a9228

#4


0  

How you can read in this tutorial, you can make a PeriodicTask, i think if you have execute a task at 1 .am. Monday's morning is because you wan to run a long cpu/mem operation, rememeber celery use ampq for enqueue tasks.

如何在本教程中阅读,您可以创建一个PeriodicTask,我认为如果您在凌晨1点执行一个任务。周一的早上是因为你想运行长时间的cpu/mem操作,记得芹菜用ampq来完成任务。

#5


0  

While @asksol's answer still holds, the api has been updated. For celery 4.1.0, I have to import crontab and periodic_task as follows:

虽然@asksol的答案仍然成立,但api已经得到了更新。对于芹菜4.1.0,我需要导入crontab和periodic_task如下:

from celery.schedules import crontab
from celery.task import periodic_task

#1


27  

The recently released version 1.0.3 supports this now, thanks to Patrick Altman!

最近发布的1.0.3版本现在支持这个功能,这要感谢Patrick Altman!

Example:

例子:

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:

更多信息请参见changelog:

http://celeryproject.org/docs/changelog.html

http://celeryproject.org/docs/changelog.html

#2


26  

Use

使用

YourTask.apply_async(args=[some, args, here], eta=when)

And at the end of your task, reschedule it to the next time it should run.

在你的任务结束时,将它重新安排到下一次应该运行的时间。

#3


5  

I have just submitted a patch to add a ScheduledTask to accomplish a small bit of time based scheduling versus period based:

我刚刚提交了一个补丁,添加了一个ScheduledTask来完成一小部分基于时间的调度,而不是基于时间的:

https://github.com/celery/celery/commit/e8835f1052bb45a73f9404005c666f2d2b9a9228

https://github.com/celery/celery/commit/e8835f1052bb45a73f9404005c666f2d2b9a9228

#4


0  

How you can read in this tutorial, you can make a PeriodicTask, i think if you have execute a task at 1 .am. Monday's morning is because you wan to run a long cpu/mem operation, rememeber celery use ampq for enqueue tasks.

如何在本教程中阅读,您可以创建一个PeriodicTask,我认为如果您在凌晨1点执行一个任务。周一的早上是因为你想运行长时间的cpu/mem操作,记得芹菜用ampq来完成任务。

#5


0  

While @asksol's answer still holds, the api has been updated. For celery 4.1.0, I have to import crontab and periodic_task as follows:

虽然@asksol的答案仍然成立,但api已经得到了更新。对于芹菜4.1.0,我需要导入crontab和periodic_task如下:

from celery.schedules import crontab
from celery.task import periodic_task