sch

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZeroTrigger = &zeroTrigger{}

Functions

func AddTask added in v1.0.12

func AddTask(task *Task)

AddTask add a task

func Schedule

func Schedule(name string, trigger Trigger, callback func())

Schedule schedule a task and start it

func Start added in v1.0.12

func Start()

Start start all task

func Stop added in v1.0.12

func Stop()

Stop stop all task

Types

type CronSequencer

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

func NewCronSequencer added in v1.0.12

func NewCronSequencer(cron string) *CronSequencer

func (*CronSequencer) Cron added in v1.0.12

func (cs *CronSequencer) Cron() string

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
	// 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) AddTask added in v1.0.12

func (s *Scheduler) AddTask(task *Task)

AddTask add a task

func (*Scheduler) GetTask added in v1.0.12

func (s *Scheduler) GetTask(name string) (*Task, bool)

GetTask get task by task name

func (*Scheduler) Schedule

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

Schedule schedule a task and start it

func (*Scheduler) Start added in v1.0.12

func (s *Scheduler) Start()

Start start all tasks

func (*Scheduler) Stop added in v1.0.12

func (s *Scheduler) Stop()

Stop stop all tasks

type Task

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

func GetTask added in v1.0.12

func GetTask(name string) (*Task, bool)

GetTask get task by task name

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