scheduler

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeFixedRate = iota
	ModeFixedDelay
	ModeRunOnce
	ModeDynamic
)

Variables

This section is empty.

Functions

func AddDefaultHook

func AddDefaultHook(hooks ...TaskHook)

func EnableTracing added in v0.14.0

func EnableTracing(tracer opentracing.Tracer)

EnableTracing add a default hook with provided openstracing.Tracer start/end/propagate spans during execution

Types

type Mode

type Mode int

type TaskCanceller

type TaskCanceller interface {
	Cancelled() <-chan error
	Cancel()
}

func Cron

func Cron(expr string, taskFunc TaskFunc, opts ...TaskOptions) (TaskCanceller, error)

Cron schedules a task using CRON expression Supported CRON expression is "<second> <minutes> <hours> <day of month> <month> [day of week]", where "day of week" is optional Note 1: do not support 'L' Note 2: any options affecting start time and repeat rate (StartAt, AtRate, etc.) would take no effect

func Repeat

func Repeat(taskFunc TaskFunc, opts ...TaskOptions) (TaskCanceller, error)

Repeat schedules a takes that repeat at specified time

func RunOnce

func RunOnce(taskFunc TaskFunc, opts ...TaskOptions) (TaskCanceller, error)

RunOnce schedules a task that run only once at specified time Note: any options affecting repeat rate (AtRate, WithDelay, etc.) would take no effect

type TaskFunc

type TaskFunc func(ctx context.Context) error

type TaskHook

type TaskHook interface {
	// BeforeTrigger is invoked before each time the task is triggered. TaskHook can modify execution context
	BeforeTrigger(ctx context.Context, id string) context.Context

	// AfterTrigger is invoked after the task is triggered and executed
	AfterTrigger(ctx context.Context, id string, err error)
}

type TaskOption

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

type TaskOptions

type TaskOptions func(opt *TaskOption) error

func AtRate

func AtRate(repeatInterval time.Duration) TaskOptions

AtRate option for "Fixed Interval" mode. Triggered every given interval. Long-running tasks overlap each other. Exclusive with WithDelay

func CancelOnError

func CancelOnError() TaskOptions

CancelOnError option that automatically cancel the scheduled task if any execution returns non-nil error

func Name

func Name(name string) TaskOptions

Name option to give the task a name

func StartAfter

func StartAfter(delay time.Duration) TaskOptions

StartAfter option to set task's initial trigger delay, should be positive duration Exclusive with StartAt

func StartAt

func StartAt(startTime time.Time) TaskOptions

StartAt option to set task's initial trigger time, should be future time Exclusive with StartAfter

func TaskHooks

func TaskHooks(hooks ...TaskHook) TaskOptions

TaskHooks option to add TaskHook

func WithDelay

func WithDelay(repeatDelay time.Duration) TaskOptions

WithDelay option for "Fixed Delay" mode. Triggered with given delay after previous task finished Long-running tasks will never overlap Exclusive with AtRate

Jump to

Keyboard shortcuts

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