我如何在 celery beat 中以不同的方式在工作日和周末安排我的任务?
时间表在我的settings.py文件中设置如下
{
"task_weekday": {
"task": "tasks.my_regular_task",
"schedule": crontab(minute="0-30", hour="4,5", day_of_week="mon-fri"),
"options": {"queue": "queue_name"},
},
"task_weekend": {
"task": "tasks.my_regular_task",
"schedule": crontab(minute="0-5", hour="10,12", day_of_week="sat,sun"),
"options": {"queue": "queue_name"},
},
}
Run Code Online (Sandbox Code Playgroud)
但是,当我设置它时,它在今天(2021 年 3 月 21 日星期日)运行工作日计划,而不是选择周末计划。
我将应用程序时区设置为'US/Pacific'并且CELERY_ENABLE_UTC设置为False。
设置后,我看到以下日志条目,但它运行工作日任务计划。
[2021-03-21 17:57:50,082: DEBUG/MainProcess] Current schedule:
<ScheduleEntry: task_weekday tasks.my_regular_task() <crontab: 0-30 4,5 mon-fri * * (m/h/d/dM/MY)>
<ScheduleEntry: task_weekend tasks.my_regular_task() <crontab: 0-5 10,12 sat,sun * * (m/h/d/dM/MY)>
<ScheduleEntry: celery.backend_cleanup celery.backend_cleanup() <crontab: 0 4 * * …Run Code Online (Sandbox Code Playgroud)