【问题标题】:Celery Beat sending tasks on startup (before the scheduled time)Celery Beat 在启动时发送任务(在预定时间之前)
【发布时间】:2021-07-25 23:03:18
【问题描述】:

我有一个芹菜节拍时间表:

CELERY_BEAT_SCHEDULE = {               
    "test-task": {                     
        "task": "myapp.tasks.test_task",          
        "schedule": crontab(hour=20),   # Should execute at 8pm UTC!
    }                                  
}                                      

当我执行节拍实例时,

celery --app myapp beat --loglevel DEBUG

celery beat 实例自动将任务发送给 broker:

[2021-05-03 14:12:04,022: INFO/MainProcess] Scheduler: Sending due task test-task (myapp.tasks.test_task)

有什么办法可以预防吗?该任务只应在晚上 8 点执行,并且绝不能在此之前执行。

【问题讨论】:

    标签: django celery celerybeat


    【解决方案1】:

    我也在运行类似的东西,没有问题(它不在启动时执行)。

    与您的代码的唯一区别是我也指定了分钟数,因此值得一试:

    CELERY_BEAT_SCHEDULE = {               
        "test-task": {                     
            "task": "myapp.tasks.test_task",
            "args": (),
            "schedule": crontab(minute='0', hour=20),   # Should execute at 8pm UTC!
        }                                  
    }                                      
    

    【讨论】: