django-celery-beat
django-celery-beat copied to clipboard
Issue about django-celery-beat and Crontab Expression
Currently, I have a periodic task that runs every day at a specific time, and I have set the Crontab expression accordingly:
Crontab Expression: "51 11 * * *"
Now, the issue arises when I decide to update the Crontab expression for the same task to a new time, for example:
New Crontab Expression: "51 14 * * *"
Based on my understanding, the updated task should execute at the new scheduled time during the next beat cycle. However, I have noticed that the task appears to run immediately after I update the Crontab expression, even if the current time does not match the new schedule. And this is not occurring every time, but somewhat randomly.
This is a duplicate of #537 (or at least the cause is the exactly the same).
The reasons this happens is that the crontab expression is evaluated according to when it was last run, not the current time. Easy way of demonstrating this:
Say the time is 11:30 and the last run value for the periodic task is 11:20. Now set a new periodic task to run daily at 11:25 (greater than the last run value but less than the current time). The task will run immediately.
What I have personally done to fix this is extend the DatabaseScheduler class and set the last run at value to the current time.