Documentation
¶
Index ¶
- Constants
- Variables
- func EverySpec(interval, fallback time.Duration) string
- func Initialize() *cron.Cron
- func IsConnectionLost(err error) bool
- func IsDatabaseUnavailable(err error) bool
- func IsTimeout(err error) bool
- func Names(jobs ...Job) []string
- func Register(ctx context.Context, cronScheduler *cron.Cron, jobs ...Job)
- func RunOnce(ctx context.Context, name string, jobs ...Job) error
- type Job
- type TransientCheck
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.
func IsConnectionLost ¶ added in v1.3.0
IsConnectionLost reports a dependency that dropped or refused the connection.
func IsDatabaseUnavailable ¶ added in v1.3.0
IsDatabaseUnavailable reports a database that is restarting or lost the connection, as opposed to one that rejected the query.
Types ¶
type Job ¶
type Job struct {
Name string
Spec string
Timeout time.Duration
Quiet bool
FailuresBeforeAlarm int
Transient []TransientCheck
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.
Transient extends DefaultTransientChecks with failures only the service knows to be passing.
type TransientCheck ¶ added in v1.3.0
TransientCheck tells whether a failure is one a frequent job outlives by itself, so it is logged at warning level until FailuresBeforeAlarm failures in a row.
func DefaultTransientChecks ¶ added in v1.3.0
func DefaultTransientChecks() []TransientCheck
DefaultTransientChecks are applied to every job; Job.Transient adds the ones a service knows of.