Implement catch-up behavior for cron jobs#67
Open
intersel wants to merge 1 commit intoJako:masterfrom
Open
Conversation
Add a cron_catchup system option to control how missed executions are handled. When disabled, cronjobs are always rescheduled from the current time, avoiding catch-up loops after downtime. When enabled, the existing behavior is preserved, with a safeguard against outdated nextrun values to prevent infinite execution loops.
Jako
reviewed
Apr 30, 2026
Owner
Jako
left a comment
There was a problem hiding this comment.
Maybe it is better to calculate the nextrun with a do/while loop until the nextrun is in the future. Then the additional option is not needed.
Author
|
I get the idea, but wouldn’t this risk shortening the effective interval between runs compared to the configured delay? |
Owner
|
Something like this: Then the interval between two runs remains the same and just some runs are not executed. |
Owner
|
Is this code right for you? |
Author
|
sounds good... not tested yet |
Owner
|
It would be nice, if you have time to test the suggested code. |
Author
|
I'll do my best to give you feedback in the next days... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why it is needed
When there is a server downtime or when the system cron (calling cron.php) is stopped for any reason, scheduled jobs may accumulate delay.
In the current implementation, the next run (
nextrun) is always calculated based on the previousnextrunvalue. If this value is already in the past, the newnextruncan also remain in the past.This can lead to repeated immediate executions ("catch-up loops") until the scheduler catches up with the current time. In some cases, this may cause unnecessary load or unexpected behavior, especially for jobs that are not designed to run multiple times in quick succession.
This change introduces an option to control this behavior:
This provides safer and more predictable behavior for most use cases while preserving backward compatibility.
What this PR does
Add a cron_catchup system option to control how missed executions are handled.
When disabled, cronjobs are always rescheduled from the current time, avoiding catch-up loops after downtime.
When enabled, the existing behavior is preserved, with a safeguard against outdated nextrun values to prevent infinite execution loops.