Documentation
¶
Overview ¶
Package clock is a low consumption, low latency support for frequent updates of large capacity timing manager:
1、能够添加一次性、重复性任务,并能在其执行前撤销或频繁更改。 2、支持同一时间点,多个任务提醒。 3、适用于中等密度,大跨度的单次、多次定时任务。 4、支持10万次/秒的定时任务执行、提醒、撤销或添加操作,平均延迟10微秒内 5、支持注册任务的函数调用,及事件通知。
基本处理逻辑:
1、重复性任务,流程是: a、注册重复任务 b、时间抵达时,控制器调用注册函数,并发送通知 c、如果次数达到限制,则撤销;否则,控制器更新该任务的下次执行时间点 d、控制器等待下一个最近需要执行的任务 2、一次性任务,可以是服务运行时,当前时间点之后的任意事件,流程是: a、注册一次性任务 b、时间抵达时,控制器调用注册函数,并发送通知 c、控制器释放该任务 d、控制器等待下一个最近需要执行的任务
使用方式,参见示例代码。
Index ¶
- Constants
- type Clock
- func (jl *Clock) AddJobRepeat(interval time.Duration, actionMax uint64, jobFunc func()) (jobScheduled Job, inserted bool)
- func (jl *Clock) AddJobWithDeadtime(actionTime time.Time, jobFunc func()) (jobScheduled Job, inserted bool)
- func (jl *Clock) AddJobWithInterval(actionInterval time.Duration, jobFunc func()) (jobScheduled Job, inserted bool)
- func (jl *Clock) Count() uint64
- func (jl *Clock) Reset() *Clock
- func (jl *Clock) Stop()
- func (jl *Clock) StopGraceful()
- func (jl *Clock) UpdateJobTimeout(job Job, actionTime time.Duration) (updated bool)
- func (jl *Clock) WaitJobs() uint64
- type Job
- type Task
Constants ¶
const ( // Debug debug switch Debug = false )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is jobs schedule
func (*Clock) AddJobRepeat ¶
func (jl *Clock) AddJobRepeat(interval time.Duration, actionMax uint64, jobFunc func()) (jobScheduled Job, inserted bool)
AddJobRepeat add a repeat task with interval duration
@interval: The interval between two actions of the job @actionMax: The number of job execution @jobFunc: Callback function,not nil return @jobScheduled : A reference to a task that has been scheduled. @inserted : return false ,if interval is not Positiveor jobFunc is nil
Note: when jobTimes==0,the job will be executed without limitation。If you no longer use, be sure to call the DelJob method to release
func (*Clock) AddJobWithDeadtime ¶
func (jl *Clock) AddJobWithDeadtime(actionTime time.Time, jobFunc func()) (jobScheduled Job, inserted bool)
AddJobWithDeadtime insert a timed task with time point after now
@actionTime: Execution start time. must after now @jobFunc: Callback function,not nil return @jobScheduled : A reference to a task that has been scheduled. @inserted : return false ,if actionTime before time.Now or jobFunc is nil
func (*Clock) AddJobWithInterval ¶
func (jl *Clock) AddJobWithInterval(actionInterval time.Duration, jobFunc func()) (jobScheduled Job, inserted bool)
AddJobWithInterval insert a timed task with time duration after now
@actionTime: Duration after now @jobFunc: Callback function,not nil return @jobScheduled: A reference to a task that has been scheduled.
func (*Clock) StopGraceful ¶
func (jl *Clock) StopGraceful()
StopGracefull stop clock ,and do once every waiting job including Once\Reapeat Note:对于任务队列中,即使安排执行多次或者不限次数的,也仅仅执行一次。
func (*Clock) UpdateJobTimeout ¶
UpdateJobTimeout update a timed task with time duration after now
@job: job identifier @actionTime: new job schedule time,must be greater than 0
type Job ¶
type Job interface {
C() <-chan Job //C Get a Chan,which can get message if Job is executed
Count() uint64 //计数器,表示已执行(或触发)的次数
Max() uint64 //允许执行的最大次数
Cancel() //撤销加载的任务,不再定时执行
// contains filtered or unexported methods
}
This code is based on the following resources: source code: https://github.com/alex023/clock.git
Job External access interface for timed tasks
type Task ¶
func (*Task) AddJobRepeat ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
client
command
|
|
|
pkg
|
|
|
rbtree
Package rbtree implements operations on Red-Black tree.
|
Package rbtree implements operations on Red-Black tree. |
|
rbtree/example/example_int
command
|
|
|
rbtree/example/example_string
command
|
|
|
rbtree/example/example_struct
command
|
|