Skip to content
/ timing Public

一个适用于一次性或者需要重复性任务的执行器,可配合常驻服务实现自动执行定时任务(非类linux CronTab)

License

Notifications You must be signed in to change notification settings

lwl1989/timing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timing

A one-off timed task.

Thanks

robfig/cron

ChangeLog

[2018-05-22] Add Export

[2018-05-22] Renamed Tasks to TaskScheduler

[2019-02-23] Add task interface and can rewrite the logic

Quick Start

scheduler := NewScheduler()

scheduler.Start()

scheduler.AddFunc(time.Now().Unix()+1, func() {
	fmt.Println("one second after")
})

scheduler.AddTask(&Task{
	Job:FuncJob(func() {
    		fmt.Println("hello task2")
    }),
    RunTime:time.Now().Unix()+4,
})

//block it

add task

//10 seconds print one
scheduler.AddFuncSpace(10, func() {
	fmt.Println("one second after")
})


scheduler.AddTask(&Task{
	Job:FuncJob(func() {
    		fmt.Println("hello task")
    }),
    Spacing:4 //4 seconds send one
})

scheduler.AddTask(&Task{
	Job:FuncJob(func() {
    		fmt.Println("hello task2")
    }),
    Spacing:4 //4 seconds send one
    Number: 5 //exec 5 num go stop
})

scheduler.AddTask(&Task{
	Job:FuncJob(func() {
    		fmt.Println("hello task3")
    }),
    Spacing:4 //4 seconds send one
    EndTime: 1999999999   // at 199999999 go stop
})

task interface

If you need rewrite a new task

implement TaskInterface

type TaskInterface interface {
    TaskGetInterface
    TaskSetInterface
}

type TaskSetInterface interface {
    SetJob(job Job) TaskSetInterface
    SetRuntime(runtime int64) TaskSetInterface
    SetUuid(uuid string) TaskSetInterface
    SetSpacing(spacing int64) TaskSetInterface
    SetEndTime(endTime int64) TaskSetInterface
    SetRunNumber(number int) TaskSetInterface
}

type TaskGetInterface interface{
    RunJob()
    GetJob()  Job
    GetUuid() string
    GetRunTime() int64
    GetSpacing() int64
    GetEndTime() int64
    GetRunNumber() int
}

next

  1. distributed the cron task

Example

Order expire, change order status => fail Timing of the send message

and more

About

一个适用于一次性或者需要重复性任务的执行器,可配合常驻服务实现自动执行定时任务(非类linux CronTab)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages