Repository navigation
fix(scheduler): report real cron runs when a time window is set - #255
Open
ThomasBarth04 wants to merge 1 commit into
Open
ThomasBarth04 wants to merge 1 commit into
ThomasBarth04 wants to merge 1 commit into
Conversation
With a cron schedule plus a window, NextRun/NextRuns snapped any tick outside the window to the window start. Cron never fires at that time, so `preview`, `doctor` and the daemon's startup log showed runs that would not happen (e.g. cron "0 * * * *" with window 22:30-06:00 showed 22:30 instead of 23:00; cron "0 2 * * *" with window 09:00-17:00 showed a daily 09:00 run although the job never runs). Now cron mode returns the first cron tick inside the window, and ErrNoRunInWindow when none exists. Interval mode keeps snapping, since its loop really does wake at the window start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
When
schedule.cronandschedule.windoware both set,NextRun()andNextRuns()move any cron tick that falls outside the window to the window start time. Cron never fires at that time, though. The job runs only on cron ticks, andrunJobsskips the ones outside the window. Sonightshift preview,nightshift doctorand the daemon'sdaemon running next_run=…log line show runs that never happen.Examples:
cron: "0 * * * *", window22:30–06:00cron: "15 */2 * * *", window09:00–17:00cron: "0 2 * * *", window09:00–17:00The last case is the worst: the config is silently broken, yet
doctorreportsschedule OK, next run … 09:00.Fix
nextCronRunInWindow, which returns the first cron tick inside the window. When a tick falls outside the window, it jumps straight to the next window opening instead of checking every tick in between. The search stops after 5 years, the same limit robfig/cron uses.NextRunsandupdateNextRunLockednow use this function. If the cron never fires inside the window,NextRunsreturns a newErrNoRunInWindow.doctornow showscron schedule never fires inside time windowas a warning instead of "OK". The daemon logs a warning instead ofnext_run=0001-01-01….Tests
TestNextCronRunInWindowwith fixed times: tick already inside the window, skipping to the first tick inside it, no snapping to the window start, a weekday-only cron across a weekend, and a cron that never fires inside the window.TestNextRuns_CronWithWindowchecks that every returned run is a real cron tick inside the window.TestNextRuns_CronNeverInWindowchecks that the new error is returned.gofmt,go vet ./...andgo test ./...all pass.🤖 Generated with Claude Code