feat(scheduler): cron parser + in-process tick loop (PRE-6)#1574
Merged
Conversation
New bounded context for cron-driven recurring runs. Reads schedule rows written via state.ScheduleStore (PRE-5 #1568), fires due jobs through a caller-supplied Dispatcher, advances next_fire_at via the cron parser. Components: - internal/scheduler/cron.go — 5-field cron parser supporting *, N, N-M, */N, N-M/N, comma lists. cron(8) day-of-month/day-of-week OR semantics when both fields are explicit. NextFire walks forward minute-by-minute, capped at 5 years to surface impossible expressions like "0 0 31 2 *". - internal/scheduler/scheduler.go — Scheduler struct with Start/Stop lifecycle, configurable tick interval (default 30s), pluggable Dispatcher interface so this package stays independent of the runner/executor wiring. Tick() exposed for deterministic test driving. Fires once on Start so freshly-booted servers don't wait the full tick before processing overdue rows. Behaviour notes: - Bad cron expressions advance next_fire_at by 24h to prevent churn while the operator fixes the row. - Failed Dispatch still advances next_fire so a chronically-broken dispatcher doesn't hot-loop. Tests cover parser shapes (every-min/top-of-hour/weekday/range-step), NextFire correctness (incl. impossible-expression error), tick loop (due-only, future-skip, bad-cron, dispatch-err, Start fires immediately). Closes #1571.
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.
Closes #1571. Phase 0 child of Epic #1565.
What
New bounded context `internal/scheduler/` with two components:
Behaviour notes
Tests
659 LOC, 4 new files.
Acceptance vs #1571