Documentation
¶
Overview ¶
Package scheduler provides stable background job scheduling primitives.
Runner executes jobs immediately on start and then on their configured intervals. Panics inside scheduled jobs are recovered, logged, and recorded as failed runs so later intervals can continue. At most one schedule is active per job name, even if the same runner is started more than once or duplicate named jobs are configured, and same-name jobs never overlap with themselves while a prior run is still in flight.
Recorder persistence failures are treated as observability failures rather than job failures. The runner should surface them through logging and any configured callback hook, but it should not rerun the job immediately or stop future intervals after the job function itself has already completed. Final run persistence uses a short-lived cleanup context so graceful shutdown can still record outcomes after the job function returns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LastRunProvider ¶
type LastRunProvider interface {
LastFinished(ctx context.Context, jobName string) (time.Time, bool, error)
}
LastRunProvider exposes last finished run for a job.
type Recorder ¶
type Recorder interface {
Record(ctx context.Context, jobName string, startedAt, finishedAt time.Time, success bool, errMsg string) error
}
Recorder persists job runs.
Persistence errors are observability failures. Runner implementations should surface them, but a failed write must not retroactively change the outcome of a job function that already ran to completion.
type RecorderFailure ¶ added in v2.1.0
type RecorderFailure struct {
JobName string
StartedAt time.Time
FinishedAt time.Time
Success bool
ErrMsg string
Err error
}
RecorderFailure captures the context for a failed run-record write.
type RecorderFailureHandler ¶ added in v2.1.0
type RecorderFailureHandler interface {
OnRecorderFailure(ctx context.Context, failure RecorderFailure)
}
RecorderFailureHandler receives recorder write failures.
type RecorderFailureHandlerFunc ¶ added in v2.1.0
type RecorderFailureHandlerFunc func(context.Context, RecorderFailure)
RecorderFailureHandlerFunc turns a function into a RecorderFailureHandler.
func (RecorderFailureHandlerFunc) OnRecorderFailure ¶ added in v2.1.0
func (f RecorderFailureHandlerFunc) OnRecorderFailure( ctx context.Context, failure RecorderFailure, )
OnRecorderFailure calls the underlying function.
type RecorderFunc ¶
type RecorderFunc func(ctx context.Context, jobName string, startedAt, finishedAt time.Time, success bool, errMsg string) error
RecorderFunc turns a function into a Recorder.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes jobs on a ticker until ctx is cancelled.
func New ¶
func New(log Logger, rec Recorder, last LastRunProvider, jobs ...Job) *Runner
New creates a Runner.
func (*Runner) SetRecorderFailureHandler ¶ added in v2.1.0
func (r *Runner) SetRecorderFailureHandler(handler RecorderFailureHandler)
SetRecorderFailureHandler configures a callback for recorder persistence failures. Set it before calling Start.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package migrations provides stable scheduler migration helpers.
|
Package migrations provides stable scheduler migration helpers. |