Documentation
¶
Overview ¶
Package schedule provides cron-style task scheduling on robfig/cron with per-job panic recovery, optional overlap skipping, and graceful stop as an application runner.
The scheduler is single-instance in this version: running N replicas executes every job N times. Run it in one instance (or a dedicated binary) when deploying multiple replicas.
Index ¶
- type JobOption
- type Options
- type Scheduler
- func (s *Scheduler) Cron(spec, name string, job func(context.Context) error, opts ...JobOption) error
- func (s *Scheduler) Daily(name string, job func(context.Context) error, opts ...JobOption) error
- func (s *Scheduler) Every(interval time.Duration, name string, job func(context.Context) error, ...) error
- func (s *Scheduler) Hourly(name string, job func(context.Context) error, opts ...JobOption) error
- func (s *Scheduler) Run(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JobOption ¶
type JobOption func(*jobConfig)
JobOption customizes one scheduled job.
func SkipIfRunning ¶
func SkipIfRunning() JobOption
SkipIfRunning skips a tick while the previous run of the same job is still executing. Overlapping runs are allowed by default.
type Options ¶
type Options struct {
Logger *slog.Logger // defaults to slog.Default()
Location *time.Location // defaults to time.Local
// StopTimeout bounds the wait for running jobs on stop, defaulting to 10s.
StopTimeout time.Duration
}
Options defines an implementation type used by this package.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs named jobs on cron schedules.
func (*Scheduler) Cron ¶
func (s *Scheduler) Cron(spec, name string, job func(context.Context) error, opts ...JobOption) error
Cron schedules job with a five-field cron spec such as "*/5 * * * *". The spec is validated immediately. A failing or panicking job is logged and never stops the scheduler or the application.
func (*Scheduler) Every ¶
func (s *Scheduler) Every(interval time.Duration, name string, job func(context.Context) error, opts ...JobOption) error
Every schedules job at a fixed interval of at least one second.