scheduler

package
v0.0.0-...-688b8c7 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoNotRerun

func DoNotRerun(err error) error

DoNotRerun is a special wrapper for the error so it knows not to be reran.

func InitScheduler

func InitScheduler()

InitScheduler is used to initialise the scheduler. This should only be called once.

Types

type Job

type Job[T any] struct {
	// contains filtered or unexported fields
}

Job is used to define a schedule job handler. Should not be created manually, use NewJob instead.

func NewJob

func NewJob[T any](name string, hn func(context.Context, T) error) Job[T]

NewJob is used to create a new scheduler job type. The returned struct can be used to interact with it.

func (Job[T]) RunAndBlock

func (j Job[T]) RunAndBlock(ctx context.Context, body T) error

RunAndBlock is used to run the job right away and block until it is done. This does not put it into the scheduler queue and is mainly used for config testing.

func (Job[T]) Schedule

func (j Job[T]) Schedule(ctx context.Context, body T, metadata Metadata, in time.Duration) (string, error)

Schedule is used to add a job to the scheduler with the first fire either in the duration specified or if that is zero when the refire duration is.

func (Job[T]) ScheduleImmediately

func (j Job[T]) ScheduleImmediately(ctx context.Context, body T, metadata Metadata) (string, error)

ScheduleImmediately is used to add a job to the scheduler with the first fire to be as soon as it is picked up by the scheduler. Returns the task ID and error.

type Metadata

type Metadata struct {
	// Retries is the number of times this task will be retried with each run decrementing 1.
	// A start of 0 here means unlimited.
	Retries uint

	// Timeout is used to define the timeout of the job.
	Timeout time.Duration

	// RefireDuration is the duration that should be slept if this is refired.
	RefireDuration time.Duration
}

Metadata is used to define the metadata relating to a scheduler.

Jump to

Keyboard shortcuts

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