Documentation
¶
Overview ¶
Package cron schedules recurring jobs using cron expressions.
hex/cron wraps robfig/cron/v3 with a small facade that fits the hex provider lifecycle: consumers register jobs during Register/Boot, Start begins the ticker in the background, and Stop drains running jobs.
A job is a function that takes a context and returns an error. Errors are logged; they never crash the scheduler. Panics inside a job are recovered so one bad job does not take down the rest.
Example:
sched := cron.New()
if err := sched.Schedule("sync-releases", "*/5 * * * *", func(ctx context.Context) error {
return svc.Sync(ctx)
}); err != nil {
return err
}
sched.Start()
defer sched.Stop(ctx) // waits for in-flight jobs
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron is a hex-owned cron scheduler.
func New ¶
New returns a Cron with the given options. Timezone defaults to time.Local; use robfig options via WithRobfigOption for advanced control.
func (*Cron) Remove ¶
Remove unregisters the job with the given name. Returns true if a job was removed, false if no job with that name was registered.
func (*Cron) Schedule ¶
Schedule registers job under name to run on spec. Returns an error if the spec is invalid or a job with the same name is already registered.
type Job ¶
Job is a function executed on a cron schedule. The context is derived from the scheduler's root context so shutdown cancellation reaches all jobs.