task

package
v0.0.0-...-6a6dcdd Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AdminTaskList map[string]Tasker
)

Functions

func AddTask

func AddTask(taskname string, t Tasker)

func DeleteTask

func DeleteTask(taskname string)

func StartTask

func StartTask()

func StopTask

func StopTask()

Types

type Case

type Case struct {
	Key     string //任务唯一标识
	Spec    string
	Local   bool //local为true,代表为本地任务,不注册到sysmain,此时Spec非空,注册后会立即启动
	Handler Handler
	Params  string
}

func (*Case) Run

func (m *Case) Run(params string) error

type Client

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

func Init

func Init(app string, sysmainUrl string, secret string, host string, port int) *Client

Init remoteUrl sysmain http接口地址 secret sysmain http接口秘钥 host 本机地址 port 本机服务端口

func (*Client) Event

func (m *Client) Event(in map[string]string) (err error)

Event Params:

Sign      string
Timestamp string
Key   string
Event string //start、stop、once
Spec  string

func (*Client) Register

func (m *Client) Register(cases ...Case)

Register 注册任务

func (*Client) Status

func (m *Client) Status(in map[string]string) (out map[string]string, err error)

type Handler

type Handler func(params string) error

type MapSorter

type MapSorter struct {
	Keys []string
	Vals []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
	SpecStr  string
	DoFunc   Handler
	Prev     time.Time
	Next     time.Time
	Errlist  []*taskerr
	ErrLimit int
}

func NewTask

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

func (*Task) GetNext

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

func (*Task) GetPrev

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

func (*Task) GetSpec

func (t *Task) GetSpec() string

func (*Task) GetStatus

func (t *Task) GetStatus() string

func (*Task) Run

func (t *Task) Run() error

func (*Task) SetCron

func (t *Task) SetCron(spec string)

SetCron some signals:

*: any time
,:  separate signal

   -:duration

/n : do as n times of time duration

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

0/30 * * * * *                        every 30s
0 43 21 * * *                         21:43
0 15 05 * * *                       05:15
0 0 17 * * *                          17:00
0 0 17 * * 1                          17:00 in every Monday
0 0,10 17 * * 0,2,3                   17:00 and 17:10 in every Sunday, Tuesday and Wednesday
0 0-10 17 1 * *                       17:00 to 17:10 in 1 min duration each time on the first day of month
0 0 0 1,15 * 1                        0:00 on the 1st day and 15th day of month
0 42 4 1 * *                        4:42 on the 1st day of month
0 0 21 * * 1-6                      21:00 from Monday to Saturday
0 0,10,20,30,40,50 * * * *           every 10 min duration
0 */10 * * * *                  every 10 min duration
0 * 1 * * *                   1:00 to 1:59 in 1 min duration each time
0 0 1 * * *                   1:00
0 0 */1 * * *                  0 min of hour in 1 hour duration
0 0 * * * *                   0 min of hour in 1 hour duration
0 2 8-20/3 * * *                8:02, 11:02, 14:02, 17:02, 20:02
0 30 5 1,15 * *                 5:30 on the 1st day and 15th day of month

func (*Task) SetNext

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

func (*Task) SetPrev

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

type Tasker

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

Jump to

Keyboard shortcuts

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