scheduler

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTaskAlreadyExists        = errors.New("task already exists")
	ErrTaskNotFound             = errors.New("task not found")
	ErrIntervalTimeoutBothSet   = errors.New("only one of Interval or Timeout must be set")
	ErrIntervalTimeoutNoneSet   = errors.New("either Interval or Timeout must be set")
	ErrTaskFuncNotSet           = errors.New("TaskFunc must be set")
	ErrIntervalDurationTooShort = errors.New("interval duration must be greater than 1 second")
	ErrTimeoutDurationTooShort  = errors.New("timeout duration must be greater than 1 second")
	ErrSchedulerRunning         = errors.New("scheduler is already running")
	ErrSchedulerNotRunning      = errors.New("scheduler is not running")
)

Functions

This section is empty.

Types

type Options

type Options struct {
	Interval time.Duration
	Logger   *zerolog.Logger
	AutoRun  bool
}

type Scheduler

type Scheduler interface {
	Start() error
	Stop()
	Running() bool
	GetTask(string) (TaskDefinition, bool)
	ScheduleTask(string, TaskOptions) error
	StopTask(string) error
	TotalTasks() int
}

func New

func New(opts Options) Scheduler

type TaskDefinition

type TaskDefinition struct {
	Name string
	Func TaskFunc
	// contains filtered or unexported fields
}

type TaskFunc

type TaskFunc func(context.Context)

type TaskOptions

type TaskOptions struct {
	// Interval is the time between each task run.
	// Timeout OR Interval must be set.
	Interval time.Duration
	// Timeout is the maximum time the task is allowed to run
	// before it is forcefully stopped.
	// Timeout OR Interval must be set.
	Timeout time.Duration
	// Overwrite indicates whether to overwrite the task if it already exists.
	// If set to false, an error will be returned if the task already exists.
	// If set to true, the task will be overwritten with the new task and any existing timers will be reset.
	Overwrite bool
	// TaskFunc is the function to run when the task is scheduled.
	TaskFunc TaskFunc
}

Jump to

Keyboard shortcuts

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