schedule

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTask

func AddTask(taskname string, t Tasker)

func DelTask

func DelTask(taskname string)

func GetAllTask

func GetAllTask() map[string]Tasker

func StartTask

func StartTask()

func Stats

func Stats() map[string]TaskStats

task stats

func StopTask

func StopTask()

Types

type MapSorter

type MapSorter struct {
	Keys []string
	Vals []Tasker
}

sort map for tasker

func NewMapSorter

func NewMapSorter(m map[string]Tasker) *MapSorter

func (*MapSorter) Len

func (ms *MapSorter) Len() int

func (*MapSorter) Less

func (ms *MapSorter) Less(i, j int) bool

func (*MapSorter) Sort

func (ms *MapSorter) Sort()

func (*MapSorter) Swap

func (ms *MapSorter) Swap(i, j int)

type Schedule

type Schedule struct {
	Second uint64
	Minute uint64
	Hour   uint64
	Day    uint64
	Month  uint64
	Week   uint64
}

func (*Schedule) Next

func (s *Schedule) Next(t time.Time) time.Time

type Task

type Task struct {
	Taskname string
	Spec     *Schedule
	DoFunc   TaskFunc
	Prev     time.Time
	Next     time.Time
	Errlist  []*taskerr //errtime:errinfo
	ErrLimit int        //max length for the errlist 0 stand for there' no limit
}

func NewTask

func NewTask(tname string, spec string, f TaskFunc) *Task

func (*Task) GetNext

func (tk *Task) GetNext() time.Time

func (*Task) GetPrev

func (tk *Task) GetPrev() time.Time

func (*Task) GetStatus

func (tk *Task) GetStatus() string

func (*Task) Run

func (tk *Task) Run() error

func (*Task) SetCron

func (t *Task) SetCron(spec string)

还可以用一些特殊符号:

*: 表示任何时刻
,: 表示分割,如第三段里:2,4,表示2点和4点执行

   -:表示一个段,如第三端里: 1-5,就表示1到5点

/n : 表示每个n的单位执行一次,如第三段里,*/1, 就表示每隔1个小时执行一次命令。也可以写成1-23/1.

///////////////////////////////////////////////////////

0/30 * * * * *                        每30秒 执行
0 43 21 * * *                         21:43 执行
0 15 05 * * *                        05:15 执行
0 0 17 * * *                          17:00 执行
0 0 17 * * 1                          每周一的 17:00 执行
0 0,10 17 * * 0,2,3                   每周日,周二,周三的 17:00和 17:10 执行
0 0-10 17 1 * *                       毎月1日从 17:00到7:10 毎隔1分钟 执行
0 0 0 1,15 * 1                        毎月1日和 15日和 一日的 0:00 执行
0 42 4 1 * *                         毎月1日的 4:42分 执行
0 0 21 * * 1-6                       周一到周六 21:00 执行
0 0,10,20,30,40,50 * * * *            每隔10分 执行
0 */10 * * * *                     每隔10分 执行
0 * 1 * * *                       从1:0到1:59 每隔1分钟 执行
0 0 1 * * *                       1:00 执行
0 0 */1 * * *                      毎时0分 每隔1小时 执行
0 0 * * * *                       毎时0分 每隔1小时 执行
0 2 8-20/3 * * *                   8:02,11:02,14:02,17:02,20:02 执行
0 30 5 1,15 * *                    1日 和 15日的 5:30 执行

func (*Task) SetNext

func (tk *Task) SetNext(now time.Time)

func (*Task) SetPrev

func (tk *Task) SetPrev(now time.Time)

type TaskFunc

type TaskFunc func() error

type TaskStats

type TaskStats struct {
	RunTimes int64
	ErrTimes int64
	Prev     time.Time
	Next     time.Time
}

type Tasker

type Tasker interface {
	GetStatus() string
	Run() error
	SetNext(time.Time)
	GetNext() time.Time
	SetPrev(time.Time)
	GetPrev() time.Time
}

func GetTask

func GetTask(name string) Tasker

Jump to

Keyboard shortcuts

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