scheduler

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default health ticker period.
	DefaultHealthTickPeriod time.Duration = 1 * time.Second

	// Default channel buffer size.
	//
	// This should be sufficiently big enough to prevent blocking.
	DefaultChannelBufferSize int = 256
)
View Source
const (
	// Number of seconds before a task is considered late.
	LateTaskDelay time.Duration = 5 * time.Second
)

Variables

View Source
var (
	ErrJobRunAtZero       = errors.Base("job run-at is zero")
	ErrJobNoTarget        = errors.Base("no job target specified")
	ErrJobAmbiguousTarget = errors.Base("job target is ambiguous")
)

Functions

func InitPrometheus

func InitPrometheus(reg prometheus.Registerer)

Initialise Prometheus metrics for this module.

Types

type Config

type Config struct {
	Name             string                // Scheduler name.
	HealthTickPeriod time.Duration         // Health tick period.
	Health           health.Reporter       // Health status reporter.
	Prometheus       prometheus.Registerer // Prometheus registerer.
	AddBuffer        int                   // Size of `add` buffer.
	WorkBuffer       int                   // Size of `work` buffer.
}

Scheduler configuration.

func NewConfig

func NewConfig(
	name string,
	tick time.Duration,
	hlth health.Reporter,
	addBuff, workBuff int,
) *Config

Create a new scheduler configuration instance.

func NewDefaultConfig

func NewDefaultConfig() *Config

Create a new default scheduler configuration instance.

type Job

type Job interface {
	Validate() error
	Resolve(context.Context) error

	Object() Task
	Function() JobFn
}

func InsertJob

func InsertJob(jobs []Job, njob Job) ([]Job, error)

Insert a job into a list of jobs.

func MakeJob

func MakeJob(obj Task, fn JobFn) Job

Create a new job.

type JobFn

type JobFn func(context.Context) error

Job function.

type Priority

type Priority struct {
	// contains filtered or unexported fields
}

Priority scheduler

Instance is single-use; create a new instance to restart.

func NewPriority

func NewPriority(ctx context.Context, cnf *Config) *Priority

Return a new priority scheduler instance.

func (*Priority) Done

func (s *Priority) Done() <-chan struct{}

Has the priority scheduler done processing?

func (*Priority) Health

func (s *Priority) Health() health.Reporter

Return the health reporter for the priority scheduler.

func (*Priority) Name

func (s *Priority) Name() string

Return the name of the priority scheduler.

func (*Priority) Next

func (s *Priority) Next(ctx context.Context) (TimedJob, bool)

Get the next task in the work channel.

func (*Priority) Start

func (s *Priority) Start()

Start the scheduler.

Must be called once before use.

func (*Priority) Stop

func (s *Priority) Stop()

Stop the priority scheduler.

func (*Priority) Submit

func (s *Priority) Submit(task TimedJob) error

Add a task to the priority scheduler.

func (*Priority) Wait

func (s *Priority) Wait(ctx context.Context) error

Wait for the goroutine created by `Start`.

func (*Priority) Work

func (s *Priority) Work() <-chan TimedJob

Get the current work channel for the priority scheduler.

type Task

type Task interface {
	Execute(context.Context) error
}

type TimedJob

type TimedJob interface {
	Job

	RunAt() time.Time
}

func InsertTimedJob

func InsertTimedJob(jobs []TimedJob, njob TimedJob) ([]TimedJob, error)

Insert a timed job into a list of jobs.

func MakeTimedJob

func MakeTimedJob(runAt time.Time, obj Task, fn JobFn) TimedJob

Create a new timed job.

Jump to

Keyboard shortcuts

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