Your Cronjobs should not rely on a perfect schedule

Posted Almost 10 years ago. Visible to the public. Repeats.

Due to network or hardware failures, it can happen that one of your cronjobs will not run at the time you specify in the schedule. Your code should be built in a way that it can be re-run at a later time (when the failure is resolved).

For example, if you are synchronizing data with another service once every day, your cronjob should not only synchronize changes from the last 24 hours. If you do this and a network failure will delay the execution of your job by 5 hours, you will only synchronize changes from hour 6-29, but forget changes from hour 1-4.

Instead your cronjob should remember the last time a sync was performed successfully, and sync all the changes that happened after that.

Henning Koch
Last edit
Over 6 years ago
Henning Koch
Keywords
background, tasks, craken, whenever
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2014-08-07 07:35)