小编Chi*_*get的帖子

如何在 Django 中为 celery beat 设置不同的工作日/周末时间表?

我如何在 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)

django cron celery django-celery celerybeat

10
推荐指数
1
解决办法
134
查看次数

标签 统计

celery ×1

celerybeat ×1

cron ×1

django ×1

django-celery ×1