Repository navigation
feat(core): in-tree cron and @every schedule parser (#578) - #604
Merged
Merged
Conversation
Part of the automation ledger core: 5-field cron with the Vixie/cronie day-of-month/day-of-week rule, macros and @every durations, with next-occurrence math and owed-occurrence spans. UTC only; zones follow in #580. Malformed and never-firing expressions are rejected with a precise reason. Property-tested against a minute-walking oracle.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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.
What
First half of the automation ledger core (#578): a small in-tree schedule parser in
tole-core— 5-field cron, the@hourly/@daily/… macros and@every <duration>— with next-occurrence math. Pure and UTC-only: times are Unix seconds passed in by the caller, nothing reads a clock. The ledger (claim, fold, recovery, catch-up) follows in a second PR on the same issue, stacked on this one.Why
Part of #578 (epic #577). The scheduler must validate a schedule on save and never "just not run" (design
docs/automation-design.md§2 P5, §4). The issue and design ask for an in-tree parser over a crate:Cargo.lockhas no cron crate, and the widely usedcroncrate pullschronoandnomintotole-core, which embedders build--no-default-features. No new dependency here.The PR is split to stay reviewable (the full #578 change is ~2.5k lines with tests); this part is ~740 lines and self-contained.
Changes
crates/tole-core/src/cron.rs(new):Schedule::parse/next_after/span, Hinnant civil-date helpers.*,N,A-B,*/S,A-B/S, comma lists; month and weekday names (case-insensitive); weekday 0 and 7 are Sunday.N/Sis rejected as ambiguous (implementations disagree) with a hint to writeN-MAX/S.*(so*and*/2) is unrestricted; if either day field is unrestricted, both must match (AND); if both are restricted, either may match (OR):0 0 13 * 5= every 13th and every Friday.60: value 60 out of range 0-59", "range 5-2 is reversed", "step 0 out of range"). An expression that can never fire (0 0 30 2 *) is rejected at parse time; a search over one 400-year Gregorian cycle (146 097 days, a whole number of weeks) is a complete check.@every/every: unitsd h m s(1h30m), at least 60 s, at most 366 days; occurrences areanchor + k·period,k ≥ 1.span(after, until, anchor)returns first/last/count of owed occurrences (O(1) for@every), which the ledger uses to record every skipped occurrence.next_after; the expression text and the log format do not change.crates/tole-core/src/lib.rs:pub mod cron;.docs/epics.md: Track E status — feat(core): append-only ledger core — claim, fold, recovery and cron parser #578 in progress, parser landed (the README status line is updated with the ledger PR, which is the first user-relevant piece).crates/tole-core/tests/cron_schedule.rs(new): parser tables, dom/dow semantics, month ends and leap years (2024, 2000, 2100, 2096→2104),span, and a property test (below).Testing
next_aftermust equal a brute-force minute walker that keeps its own calendar counters (independent of the civil-date code under test) over a 120-day window, plus three chained occurrences each. Teeth: with the month-skip deliberately broken (m >= 11instead ofm == 12), the oracle test and the month-end test go red; restored, green.cargo fmt --all— cleancargo clippy --workspace --all-targets -- -D warnings— cleancargo test --workspace— 1326 passed, 0 failedcargo build -p tole-core --no-default-featuresandcargo test -p tole-core --no-default-features— pass (434 passed, 0 failed)cora review --no-llm --base origin/develop(cora 0.20.0, deterministic rules) — no issues foundcargo build --release -p tole-cli): measured in the ledger PR, see there