scheduler

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultJobTimeout caps a job that does not set a limit of its own.
	DefaultJobTimeout = 5 * time.Minute

	// DefaultTransientFailures is how many failures in a row a job survives quietly. A short
	// outage of the database or the network is cured by the next tick, so an alert is only
	// worth raising once the work has been stuck that many runs.
	DefaultTransientFailures = 3
)
View Source
const DefaultTickInterval = 5 * time.Second

DefaultTickInterval is used when a configured interval is missing or malformed.

Variables

This section is empty.

Functions

func EverySpec

func EverySpec(interval time.Duration) string

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.

func Initialize

func Initialize() *cron.Cron

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 Register

func Register(ctx context.Context, cronScheduler *cron.Cron, jobs ...Job)

Register adds jobs to the scheduler. The context belongs to the application, not to a single run: canceling it stops the jobs that are in flight.

Types

type Job

type Job struct {
	Name              string
	Spec              string
	Timeout           time.Duration
	Quiet             bool
	TransientFailures int
	Run               func(ctx context.Context) error
}

Job describes a scheduled task: when it runs, how long it may take and what it does.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL