Skip to main content

Module schedule

Module schedule 

Source
Expand description

Cron schedule math: expression parsing, next-fire, and due-check.

chrono is confined to THIS module. Every public function takes and returns SystemTime, so CronEntry, the scheduler, and the rest of forge never touch chrono - the SystemTime <-> chrono conversion happens only inside next_fire_after’s private timezone helper.

Timezone: recurring expressions evaluate in the host’s LOCAL time (standard cron / crontab semantics). The public next_fire_after hard-codes Local; the generic _in_tz helper it delegates to lets tests pin a fixed offset and stay deterministic (CI runs UTC). due_crons needs no TZ - a SystemTime is an absolute instant, so the due-check is TZ-independent.

Re-exportsΒ§

use std::time::SystemTime; πŸ”’
use chrono::DateTime; πŸ”’
use chrono::Local; πŸ”’
use chrono::TimeZone; πŸ”’
use chrono::Utc; πŸ”’
use croner::Cron; πŸ”’
use croner::errors::CronError; πŸ”’
use croner::parser::CronParser; πŸ”’
use forge_primitives::cron::CronEntry; πŸ”’
use forge_primitives::cron::CronId; πŸ”’
use forge_primitives::cron::CronKind; πŸ”’

FunctionsΒ§

due_crons πŸ”’
The crons whose next_fire is at or before now - the scheduler’s per-tick due set, in input order. Boot catch-up is just one such tick (Workspace::fire_due_crons at startup): an overdue cron is due, so it fires once and advance_or_remove_cron moves next_fire past every missed slot - catch-up-once falls out of the normal fire path, no separate boot reconcile needed.
next_fire_after
The next fire for a cron kind strictly after after, evaluated in the host’s LOCAL timezone. None for a run-once whose instant has passed, or a recurring expression that fails to parse / has no upcoming occurrence.
next_fire_after_in_tz πŸ”’
TZ-generic core of next_fire_after. Split out so tests inject a fixed offset (deterministic regardless of the host TZ) while prod passes Local.
next_recurring_fire_in_tz πŸ”’
Next occurrence of cron expr strictly after after, in tz. The sole SystemTime <-> chrono boundary: after converts in, the result converts back out, and chrono never escapes.
parse_cron πŸ”’
Parses with sloppy_ranges, which takes the shorthand step syntax (5/5 * * * *) a registered schedule may already carry; the strict default rejects it, and a schedule that stops parsing is dropped.
validate_cron_expr πŸ”’
Validate a 5-field cron expression, returning a human-readable error on failure. cron__create calls this to reject a malformed schedule at registration time with a clear message.