schedule

package
v2.0.0-...-22a6e85 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schedule

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

Schedule contains a collection of tasks and the current state of the schedule

func New

func New() *Schedule

New creates and initializes an empty Schedule.

func (*Schedule) GetTask

func (s *Schedule) GetTask(n string) *Task

GetTask returns the task named n or nil if it doesn't exist

func (*Schedule) GetTasks

func (s *Schedule) GetTasks() []*Task

GetTasks returns scheduled tasks

func (*Schedule) IsStandBy

func (s *Schedule) IsStandBy() bool

IsStandBy tells if schedule is in IsStandBy. If false, Schedule is in "normal" mode

func (*Schedule) IsTaskStandBy

func (s *Schedule) IsTaskStandBy(t *Task) bool

IsTaskStandBy tells if a task in schedule is in IsStandBy.

func (*Schedule) NewTask

func (s *Schedule) NewTask(n string, i time.Duration, jitter time.Duration, f func() (map[string]*matrix.Matrix, error), runNow bool, identifier string) error

NewTask creates new task named n with interval i. If f is not nil, f will be called to execute task when task.Run() is called. Task name n should be unique. Interval i should be positive. The order in which tasks are added is maintained: GetTasks() will return tasks in FIFO order.

func (*Schedule) NewTaskString

func (s *Schedule) NewTaskString(n, i string, jitter time.Duration, f func() (map[string]*matrix.Matrix, error), runNow bool, identifier string) error

NewTaskString creates a new task, the interval is parsed from string i

func (*Schedule) NextDue

func (s *Schedule) NextDue() time.Duration

NextDue tells duration until at least one task is due If no tasks are scheduled, NextDue returns an arbitrary long duration (This is useful for collectors that run background jobs and need to wait indefinitely).

func (*Schedule) Recover

func (s *Schedule) Recover()

Recover undoes StandbyMode and restores normal state of the Schedule

func (*Schedule) SetStandByMode

func (s *Schedule) SetStandByMode(t *Task, i time.Duration)

SetStandByMode initializes StandbyMode: Schedule will suspend all tasks until the critical task t has succeeded. The temporary interval i will be used for the task until the Schedule recovers to normal mode.

func (*Schedule) SetStandByModeMax

func (s *Schedule) SetStandByModeMax(t *Task, i time.Duration)

SetStandByModeMax initializes StandbyMode: Schedule will suspend all tasks until the critical task t has succeeded. The amount of time to standby will be the maximum of the task's current interval and i. That interval will be used for the task until the Schedule recovers to normal mode.

func (*Schedule) Sleep

func (s *Schedule) Sleep()

Sleep sleeps until at least one task is due

func (*Schedule) Wait

func (s *Schedule) Wait() <-chan time.Time

Wait returns a blocking channel until a task is due Similar to Sleep(), but the goroutine can wait for other jobs as well

type Task

type Task struct {
	Name string // name of the task
	// contains filtered or unexported fields
}

Task represents a scheduled task

func (*Task) GetDuration

func (t *Task) GetDuration() time.Duration

GetDuration tells duration of executing the task it assumes that the task just completed

func (*Task) GetInterval

func (t *Task) GetInterval() time.Duration

GetInterval tells the scheduled interval of the task

func (*Task) IsDue

func (t *Task) IsDue() bool

IsDue tells whether it's time to run the task

func (*Task) NextDue

func (t *Task) NextDue() time.Duration

NextDue tells time until the task is due

func (*Task) Run

func (t *Task) Run() (map[string]*matrix.Matrix, error)

Run marks the task as started and executes it

func (*Task) Start

func (t *Task) Start()

Start marks the task as started by updating timer Use this method if you are executing the task yourself and you need to register when task started. If the task has a pointer to the executing function, use Run() instead.

Jump to

Keyboard shortcuts

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