CronScheduler enqueues jobs on a schedule. Pair it with a WorkerPool that processes them.
Custom schedule#
Cron expressions and time zones#
core.Cron accepts standard five-field expressions and evaluates calendar
boundaries in the supplied location, including daylight-saving transitions.
Pass nil to use UTC. Invalid expressions return an error during setup.
Notes#
- The scheduler fires each job on the first tick after
Start, then respects the interval. - A job with an empty
IDuses that legacy process-local behavior. For durable scheduling, provide a stableIDandStartAt; the first occurrence isSchedule.Next(StartAt). - Durable cursors are persisted by the driver and advanced with compare-and-swap after enqueue. Each occurrence uses a permanent uniqueness key, so leader failover or a crash between enqueue and cursor advancement cannot duplicate it.
CronCatchUpAllenqueues missed occurrences up toMaxCatchUpper tick,CronCatchUpLatestkeeps only the latest, andCronSkipMisseddrops old occurrences while still enqueueing an occurrence reached on the current tick.CronScheduleronly enqueues — workers run viaWorkerPool.- Multiple scheduler instances are safe: only the current lease holder enqueues jobs.
- Scheduler shutdown releases leadership only when that scheduler instance still owns the lease; a stale instance cannot resign a newer leader.