fix: job scheduler delayed execution window handling and info [DHIS2-15027] #16112
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.
Summary
Main fix is to not use "now" as the last execution time when a job has not been executed before when computing the next execution time because that could lead to missing an execution and thereby deferring it indefinitely. The "last" execution must always be in the past for this computation. So now is shifted back by the maximum delay. This should be safe for any setting.
This comes with a semantic change as well (not since 2.40 but since the feature was introduced in 2.41). When creating a job it will always execute as long as now is in the window between the intended execution time and the maximum delayed execution time. This means a newly created job running every day at 7pm will run if I create it 8pm with a the setting for maximum CRON delay being longer than 1h.
Further improvements:
debug
HeartbeatJob
toHousekeeping
(was missed when the name changed)lastUpdated
field with each transition of thejobStatus
tonow()
getNextExecutionTime()
andgetMaxDelayedExecutionTime()
SchedulerEntry
now hasmaxDelayedExecutionTime
: the correct end of the execution window instant (setting dependent)secondsToNextExecutionTime
: seconds to next run, for convenience as this is server time based not user local time basedsecondsToMaxDelayedExecutionTime
: seconds to next run end of execution window (same as above)JobConfiguration
now also hasgetMaxDelayedExecutionTime()
but similar togetNextExecutionTime()
both of these are only correct 100% of the time if the setting for max delay has not been changed from its default of 4hAutomatic Testing
Existing tests were adjusted and extended to reflect the change in behaviour for newly created jobs with CRON
Manual Testing
/api/scheduler/
)4./api/scheduler
maxDelayedExecutionTime
,secondsToNextExecutionTime
andsecondsToMaxDelayedExecutionTime
and see if their values add up to your expectations