第一版时间轮任务调度实现 #1
							
								
								
									
										8
									
								
								core.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								core.go
									
									
									
									
									
								
							@ -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     // 任务的创建时间
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user