feat: cron scheduler for run-to-completion jobs (#986 slice B) - #997
Merged
Conversation
Slice B of #986: schedules persist (migration 0028, both dialects: `schedules` with an optional argv override + `schedule_runs` history) and a leader-only scheduler fires them through slice A's run_job. Semantics chosen for ETL, not messaging: a schedule fires when its cron has an occurrence between the last fire marker and now — no fire-on-create (a new "daily 03:00" waits for 03:00), and downtime over several occurrences collapses to ONE firing. The fire marker is claimed BEFORE the job runs via an atomic compare-and-set on the previous value (`IS NOT DISTINCT FROM` on pg), so a crash mid-job never double-fires and a split-brain second scheduler loses the race (scaler posture, #596). Jobs run on detached tasks so a long ETL never blocks the tick; a non-Ok outcome ('failed' = non-zero exit, 'error' = could not run) records the log tail and raises the new `job-failed` webhook alert (#930). Cron parsing via croner 3 (verified on crates.io; ~6M downloads). Request built from the spec exactly like the spawn path (creds, ${VAR} env resolution, limits, network, labels) minus public-path — a job serves no HTTP; the schedule's cmd_json overrides the argv. Tests: due-semantics table (incl. downtime collapse + unparseable cron never due/never wedges the tick), CRUD + atomic-claim roundtrip (sqlite and real pg), full gate green. Live e2e: a `* * * * *` schedule on a busybox spec fired by the real serve — history row `ok/0/"etl rodou"/166ms`, zero leftover containers. Slice C (admin UI + docs + per-schedule timeout) remains. Refs #986 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Refs #986 (slice B of 3; slice A = #996)
What
schedules(cron per spec, optional argv override, enable flag, per-schedule timeout column for slice C) +schedule_runs(statusok/failed/error, exit code, log tail, duration).jobs.rsscheduler: leader-only (scaler posture), 30 s tick. ETL semantics: fires when the cron has an occurrence since the last fire marker — no fire-on-create, downtime collapses to one firing. The marker is claimed before the run via an atomic compare-and-set (IS NOT DISTINCT FROMon pg) — crash mid-job never double-fires; a split-brain second scheduler loses the race. Jobs run detached (a long ETL never blocks the tick).Okoutcomes record the log tail and raise the newjob-failedwebhook alert (Webhooks de notificação para alertas (threshold sem canal de entrega) #930 sink; cooldown per spec applies).${VAR}env, limits, network, labels) minus public-path injection — a job serves no HTTP.croner = "3"(crates.io-verified, 3.0.1, ~6M downloads).Verification
* * * * *schedule with a cmd override on a busybox spec; the scheduler fired it unattended — history rowok | exit 0 | "etl rodou" | 166 ms, zero leftover job containers.postgres-it— the claim's stale-caller loses on both dialects).-D warnings, migration filename parity.Slice C (admin UI for schedules + run history, per-schedule timeout, docs) remains — plan on the issue.
🤖 Generated with Claude Code