Skip to main content

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 ID uses that legacy process-local behavior. For durable scheduling, provide a stable ID and StartAt; the first occurrence is Schedule.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.
  • CronCatchUpAll enqueues missed occurrences up to MaxCatchUp per tick, CronCatchUpLatest keeps only the latest, and CronSkipMissed drops old occurrences while still enqueueing an occurrence reached on the current tick.
  • CronScheduler only enqueues — workers run via WorkerPool.
  • 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.