如何安排每个月 1 日运行的celery任务?
问问题
7756 次
2 回答
15
自 Celery 3.0 以来,crontab 时间表现在支持day_of_month
和month_of_year
参数:http ://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#crontab-schedules
于 2010-12-09T14:00:06.537 回答
5
您可以使用Crontab 计划执行此操作,也可以定义它:
- 在您的 django settings.py 中:
from celery.schedules import crontab
CELERYBEAT_SCHEDULE = {
'my_periodic_task': {
'task': 'my_app.tasks.my_periodic_task',
'schedule': crontab(0, 0, day_of_month='1'), # Execute on the first day of every month.
},
}
- 在celery.py配置中:
from celery import Celery
from celery.schedules import crontab
app = Celery('app_name')
app.conf.beat_schedule = {
'my_periodic_task': {
'task': 'my_app.tasks.my_periodic_task',
'schedule': crontab(0, 0, day_of_month='1'), # Execute on the first day of every month.
},
}
于 2017-01-04T09:37:47.670 回答