Documentation
¶
Overview ¶
Package cron runs jobs on a wall-clock schedule as a supervised worker.Runnable. It is a thin, production-shaped wrapper over robfig/cron: it validates specs up front, recovers panics so one bad run cannot crash the process, threads the run context into every job, and stops gracefully when its context is canceled.
It complements the worker package: a worker.Loop fires on a fixed interval since boot ("every 5m"); a cron Scheduler fires on a wall-clock spec ("at 03:00 daily", "@hourly", "@every 1h30m"). For a job that must run on at most one replica, gate it with a lock.Locker (see `skit add cron --lock`).
Specs accept the standard 5-field cron syntax (minute hour dom month dow) and the @-descriptors (@hourly, @daily, @weekly, @monthly, @every <dur>).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
Job is one scheduled unit of work. A returned error is logged; it does not stop the schedule. Jobs receive the scheduler's run context, so a long job should honor cancellation for a prompt shutdown.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler fires registered Jobs on their cron specs. Build it, Add jobs, then hand it to a worker.Group as a Runnable. It is not safe to Add after Start.
func New ¶
New builds an empty Scheduler named name (used in logs and panic metrics). log may be nil.
func (*Scheduler) Add ¶
Add registers job to run on spec. The spec is validated immediately, so a typo fails at wiring time rather than silently never firing. jobName labels the job in logs.
func (*Scheduler) OnPanic ¶
func (s *Scheduler) OnPanic(h safetick.PanicHandler) *Scheduler
OnPanic sets a handler invoked when a job panics (e.g. to bump a metric). The panic is always recovered and logged regardless.