Documentation
¶
Index ¶
Constants ¶
const DefaultJobTimeout = 5 * time.Minute
DefaultJobTimeout caps a job that does not set a limit of its own.
const DefaultTickInterval = 5 * time.Second
DefaultTickInterval is used when a configured interval is missing or malformed.
Variables ¶
var ErrJobNotFound = errors.New("job not found")
ErrJobNotFound is returned when no job carries the requested name.
Functions ¶
func EverySpec ¶
EverySpec turns an interval into a cron spec. A non-positive interval means a broken configuration, and it must not turn into a job running every second, so the caller says what to fall back to; a non-positive fallback lands on DefaultTickInterval.
func Initialize ¶
Initialize builds a scheduler that never starts a second copy of a job that is still running: a task ticking every few seconds would otherwise overlap itself and process the same rows twice.
The seconds field is optional, so both "15 3 * * *" and "0 30 3 * * *" are valid specs and a service is free to schedule a job below the minute without rewriting the rest of its specs.
Types ¶
type Job ¶
type Job struct {
Name string
Spec string
Timeout time.Duration
Quiet bool
FailuresBeforeAlarm int
Run func(ctx context.Context) error
}
Job describes a scheduled task: when it runs, how long it may take and what it does.
FailuresBeforeAlarm is how many failures in a row a frequent job survives at warning level: a job ticking every few seconds recovers from a short database or network outage by itself, and one timeout is not worth an alert. It stays 1 unless the job says otherwise, so a rare job reports the very first failure — three silent nights of a nightly job is not a trade worth making.