第一版时间轮任务调度实现 #1

Merged
zhangdeman merged 15 commits from feature/timewheel into master 2023-09-04 20:13:17 +08:00
Showing only changes of commit e332cc44c9 - Show all commits

View File

@ -181,9 +181,10 @@ func (tw *TimeWheel) checkAndRunTask() {
//
// Date : 13:43 2023/8/4
func (tw *TimeWheel) AddTask(task *Task, byInterval bool) {
if nil != task {
// 生成 key
task.Key = wrapper.StringFromRandom(128, "").Md5().Value
// 生成 run_id
task.RunID = wrapper.StringFromRandom(128, "").Md5().Value
if nil != task && nil != task.Job {
task.Key = task.Job.GetFlag() + "_" + task.RunID
}
var pos, circle int
if byInterval {
@ -261,6 +262,7 @@ func (tw *TimeWheel) getPosAndCircleByCreatedTime(createdTime time.Time, d time.
//
// Date : 11:44 2023/8/4
type Task struct {
RunID string // 每一次运行的run id
Key string // 用来标识task对象是唯一的
Interval time.Duration // 任务周期
CreatedTime time.Time // 任务的创建时间