sch

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Schedule

func Schedule(trigger Trigger, callback func())

Schedule schedule a task

func Shutdown

func Shutdown()

Shutdown stop all task

Types

type CronSequencer

type CronSequencer struct {
	Location *time.Location
	// contains filtered or unexported fields
}

func (*CronSequencer) Next

func (cs *CronSequencer) Next(date time.Time) time.Time

* Get the next {@link Date} in the sequence matching the Cron pattern and * after the value provided. The return value will have a whole number of * seconds, and will be after the input value. * @param date a seed value * @return the next value matching the pattern

func (*CronSequencer) Parse

func (cs *CronSequencer) Parse(expression string) (err error)

Parse parse the cron exception ┌───────────── second (0 - 59) │ ┌───────────── minute (0 - 59) │ │ ┌───────────── hour (0 - 23) │ │ │ ┌───────────── day of the month (1 - 31) │ │ │ │ ┌───────────── month (1 - 12) │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday; 7 is also Sunday) │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ * * * * * * Comma ( , ): used to separate items of a list. For example, "MON,WED,FRI". Dash ( - ) : used to define ranges. For example, "1-10" Slash (/) : combined with ranges to specify step values. For example, */5 in the minutes field indicates every 5 minutes It is shorthand for the more verbose POSIX form "5,10,15,20,25,30,35,40,45,50,55,00"

type CronTrigger

type CronTrigger struct {
	CronSequencer
}

func NewCronTrigger

func NewCronTrigger(cron string) *CronTrigger

func (*CronTrigger) NextExecutionTime

func (ct *CronTrigger) NextExecutionTime(task *Task) time.Time

type DelayedTrigger

type DelayedTrigger struct {
	Delay time.Duration
}

func (*DelayedTrigger) NextExecutionTime

func (dt *DelayedTrigger) NextExecutionTime(task *Task) time.Time

type PeriodicTrigger

type PeriodicTrigger struct {
	Period       time.Duration
	InitialDelay time.Duration
	FixedRate    bool
}

func (*PeriodicTrigger) NextExecutionTime

func (pt *PeriodicTrigger) NextExecutionTime(task *Task) time.Time

type Scheduler

type Scheduler struct {
	Logger log.Logger // Error logger
	// contains filtered or unexported fields
}

Scheduler task scheduler

func Default

func Default() *Scheduler

Default returns the default Scheduler instance used by the package-level functions.

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(trigger Trigger, callback func())

Schedule schedule a task

func (*Scheduler) Shutdown

func (s *Scheduler) Shutdown()

Shutdown stop all task

type Task

type Task struct {
	Logger         log.Logger // Error logger
	Trigger        Trigger
	Callback       func()
	ScheduledTime  time.Time
	ExecutionTime  time.Time
	CompletionTime time.Time
	Error          any
	// contains filtered or unexported fields
}

func (*Task) Start

func (t *Task) Start()

func (*Task) Stop

func (t *Task) Stop() bool

type Trigger

type Trigger interface {
	NextExecutionTime(task *Task) time.Time
}

Jump to

Keyboard shortcuts

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