timer

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Timer_state_init = "ts_init"
	Timer_state_run  = "ts_run"
	Timer_state_stop = "ts_stop"
)
View Source
const (
	Timer_type_tick = "tt_tick"
	Timer_type_cron = "tt_cron"
)
View Source
const (
	Max_WeekDay = 7  //max weekday value
	Min_WeekDay = 0  //min weekday value
	Max_Month   = 12 //max month value
	Min_Month   = 1  //min month value
	Max_Day     = 31 //max day value
	Min_Day     = 1  //min day value
	Max_Hour    = 23 //max hour value
	Min_Hour    = 0  //min hour value
	Max_Minute  = 59 //max minute value
	Min_Minute  = 0  //min minute value
	Max_Second  = 59 //max second value
	Min_Second  = 0  //min second value
)
View Source
const (
	ExpressType_WeekDay = "weekday"
	ExpressType_Month   = "month"
	ExpressType_Day     = "day"
	ExpressType_Hour    = "hour"
	ExpressType_Minute  = "minute"
	ExpressType_Second  = "second"
)
View Source
const (
	DefaultPeriod = time.Second //默认执行周期

)

Variables

This section is empty.

Functions

This section is empty.

Types

type ExceptionHandleFunc

type ExceptionHandleFunc func(*TimerContext, error)

type ExpressSet

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

func (*ExpressSet) IsMatch

func (e *ExpressSet) IsMatch(t time.Time) bool

type Timer

type Timer interface {
	TimerID() string
	Context() *TimerContext

	SetTimerService(service *TimerService)
	// contains filtered or unexported methods
}

func NewTickTimer

func NewTickTimer(taskID string, isRun bool, dueTime int64, interval int64, handler TimerHandleFunc, taskData interface{}) (Timer, error)

type TimerContext

type TimerContext struct {
	TimerID   string
	TimerData interface{} //用于当前Task全局设置的数据项
	Message   interface{} //用于每次Task执行上下文消息传输
	IsEnd     bool        //如果设置该属性为true,则停止当次任务的后续执行,一般用在OnBegin中
}

type TimerHandleFunc

type TimerHandleFunc func(*TimerContext) error

type TimerInfo

type TimerInfo struct {
	TimeTicker *time.Ticker
	TaskType   string

	State   string
	DueTime int64 //开始任务的延迟时间(以毫秒为单位),如果<=0则不延迟
	// contains filtered or unexported fields
}

func (*TimerInfo) Context

func (task *TimerInfo) Context() *TimerContext

func (*TimerInfo) SetTimerService

func (task *TimerInfo) SetTimerService(service *TimerService)

func (*TimerInfo) TimerID

func (task *TimerInfo) TimerID() string

type TimerService

type TimerService struct {
	ExceptionHandler ExceptionHandleFunc
	OnBeforeHandler  TimerHandleFunc
	OnEndHandler     TimerHandleFunc
	// contains filtered or unexported fields
}

func Init

func Init() *TimerService

func (*TimerService) AddTask

func (service *TimerService) AddTask(t Timer)

func (*TimerService) NewTickTask

func (ts *TimerService) NewTickTask(taskID string, isRun bool, dueTime int64, interval int64, handler TimerHandleFunc, taskData interface{}) (Timer, error)

func (*TimerService) RemoveTask

func (service *TimerService) RemoveTask(taskID string)

func (*TimerService) SetExceptionHandler

func (ts *TimerService) SetExceptionHandler(handler ExceptionHandleFunc)

设置自定义异常处理方法

func (*TimerService) SetOnBeforeHandler

func (ts *TimerService) SetOnBeforeHandler(handler TimerHandleFunc)

func (*TimerService) SetOnEndHandler

func (ts *TimerService) SetOnEndHandler(handler TimerHandleFunc)

func (*TimerService) StartAllTask

func (ts *TimerService) StartAllTask()

func (*TimerService) StartTask

func (ts *TimerService) StartTask(taskID string)

func (*TimerService) Stop

func (ts *TimerService) Stop(name string) error

func (*TimerService) StopAllTask

func (ts *TimerService) StopAllTask()

func (*TimerService) StopTask

func (ts *TimerService) StopTask(taskID string)

type TimerTask

type TimerTask struct {
	TimerInfo
	Interval int64 `json:"interval"`
}

Jump to

Keyboard shortcuts

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