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.
},
}
You can do this using Crontab schedules and you cand define this either:
in your 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.
},
}
in celery.py config:
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.
},
}
发布评论
评论(3)
从 Celery 3.0 开始,crontab 计划现在支持
day_of_month
和
month_of_year
参数: http: //docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#crontab-schedulesSince Celery 3.0 the crontab schedule now supports
day_of_month
and
month_of_year
arguments: http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#crontab-schedules您可以使用 Crontab 计划 来完成此操作可以这样定义:
You can do this using Crontab schedules and you cand define this either:
在 app.conf.beat_schedule(Celery Beat Scheduler) 中使用下面的
crontab
:Use below
crontab
in your app.conf.beat_schedule(Celery Beat Scheduler):