task

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: 0BSD Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddCbArgs

type AddCbArgs struct {
	*TaskInfo
	Error error
}

type BanCbArgs

type BanCbArgs struct {
	Key   string
	Error error
}

type CancelCbArgs

type CancelCbArgs struct {
	Key   string
	Error error
}

type EveryDaySchedule

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

每日指定时刻调度器

func NewEveryDaySchedule

func NewEveryDaySchedule(hour, minute, second, mSecond int) *EveryDaySchedule

func (*EveryDaySchedule) Expression

func (e *EveryDaySchedule) Expression(t *TaskInfo) (nt time.Time, isValid bool)

func (*EveryDaySchedule) ToString

func (e *EveryDaySchedule) ToString() string

type ExecuteCbArgs

type ExecuteCbArgs struct {
	*TaskInfo
	Res   map[string]interface{}
	Error error
	Gid   pool.GoroutineUID
}

type ISchedule

type ISchedule interface {
	Expression(t *TaskInfo) (nt time.Time, isValid bool) // 表达式
	// Record(t *TaskInfo, cs ...int) (et []time.Time)      // 索引执行记录 返回执行时刻 time为zero时说明还没被执行
	ToString() string
}

任务调度接口

type PlanSchedule

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

指定时间点调度器

func NewPlanSchedule

func NewPlanSchedule(tList []time.Time) *PlanSchedule

func (*PlanSchedule) Expression

func (p *PlanSchedule) Expression(t *TaskInfo) (nt time.Time, isValid bool)

func (*PlanSchedule) ToString

func (p *PlanSchedule) ToString() string

type SpecSchedule

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

指定时长循环调度

func NewSpecSchedule

func NewSpecSchedule(spec time.Duration) *SpecSchedule

func (*SpecSchedule) Expression

func (p *SpecSchedule) Expression(t *TaskInfo) (nt time.Time, isValid bool)

func (*SpecSchedule) Record

func (p *SpecSchedule) Record(t *TaskInfo, cs ...int) (et []time.Time)

func (*SpecSchedule) ToString

func (p *SpecSchedule) ToString() string

type SpecTimeSchedule

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

指定时长指定次数调度器

func NewSpecTimeSchedule

func NewSpecTimeSchedule(spec time.Duration, time int) *SpecTimeSchedule

func (*SpecTimeSchedule) Expression

func (p *SpecTimeSchedule) Expression(t *TaskInfo) (nt time.Time, isValid bool)

func (*SpecTimeSchedule) ToString

func (p *SpecTimeSchedule) ToString() string

type TaskInfo

type TaskInfo struct {
	Key        string      // 任务标志key
	Task       TaskObj     // 任务方法
	LastTime   time.Time   // 最后一次执行任务的时间(未执行过时为time.Time{})
	AddTime    time.Time   // 任务添加的时间
	NextTime   time.Time   // 下次执行时间
	Count      int         // 任务执行次数
	Sche       ISchedule   // 任务计划
	HasNext    bool        // 是否还有下一次执行
	LastResult *TaskResult // 任务最后一次执行的结果
	// contains filtered or unexported fields
}

func NewTaskInfo

func NewTaskInfo(key string, task TaskObj, sche ISchedule) *TaskInfo

创建一个任务信息对象

func (*TaskInfo) Clone

func (t *TaskInfo) Clone() *TaskInfo

生成副本

func (*TaskInfo) GetAddTaskTime

func (t *TaskInfo) GetAddTaskTime() time.Time

任务添加时间

func (*TaskInfo) GetLastExecuteTime

func (t *TaskInfo) GetLastExecuteTime() (time.Time, bool)

最后一次执行时间

func (*TaskInfo) HasNextExecute

func (t *TaskInfo) HasNextExecute() bool

是否还有下一次执行

func (*TaskInfo) NextScheduleTime

func (t *TaskInfo) NextScheduleTime() time.Time

下次执行时间

func (*TaskInfo) Update

func (t *TaskInfo) Update()

执行后调用 调整任务信息 返回是否还有下一次执行

type TaskMap

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

任务字典 线程安全

func NewTaskMap

func NewTaskMap() *TaskMap

func (*TaskMap) Add

func (tm *TaskMap) Add(key string, task *TaskInfo)

添加

func (*TaskMap) AddOrSet

func (tm *TaskMap) AddOrSet(key string, task *TaskInfo)

添加或修改

func (*TaskMap) Delete

func (tm *TaskMap) Delete(key string)

删除

func (*TaskMap) Get

func (tm *TaskMap) Get(key string) *TaskInfo

获取 返回副本

func (*TaskMap) GetAll

func (tm *TaskMap) GetAll() map[string]*TaskInfo

获取所有返回副本

func (*TaskMap) IsExist

func (tm *TaskMap) IsExist(key string) bool

键是否存在

func (*TaskMap) SelectNextExec

func (tm *TaskMap) SelectNextExec() (*TaskInfo, time.Duration, bool)

选择下一个最早执行的任务

func (*TaskMap) Set

func (tm *TaskMap) Set(key string, task *TaskInfo)

存在时才修改

type TaskObj

type TaskObj func() (map[string]interface{}, error)

type TaskResult

type TaskResult struct {
	Result map[string]interface{}
	Err    error
}

func (*TaskResult) Clone

func (tr *TaskResult) Clone() *TaskResult

type TimerObj

type TimerObj func() (spec time.Duration, start, end time.Time)

func Timer

func Timer() TimerObj

计时器

type UnBanCbArgs

type UnBanCbArgs BanCbArgs

Jump to

Keyboard shortcuts

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