diff --git a/README.md b/README.md index f0304d0..609a632 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ 4.任务panic处理 5.阻塞策略处理 6.任务完成支持返回执行备注 +7.任务超时取消 (单位:秒,0为不限制) +8.失败重试次数(在参数param中,目前由任务自行处理) +9.日志查看(未完成) ``` ## Example diff --git a/executor.go b/executor.go index 757561f..132164d 100644 --- a/executor.go +++ b/executor.go @@ -107,9 +107,13 @@ func (e *executor) runTask(writer http.ResponseWriter, request *http.Request) { log.Println("任务[" + Int64ToStr(param.JobID) + "]没有注册:" + param.ExecutorHandler) return } - + cxt := context.Background() task := e.regList.Get(param.ExecutorHandler) - task.Ext, task.Cancel = context.WithCancel(context.Background()) + if param.ExecutorTimeout > 0 { + task.Ext, task.Cancel = context.WithTimeout(cxt, time.Duration(param.ExecutorTimeout)*time.Second) + } else { + task.Ext, task.Cancel = context.WithCancel(cxt) + } task.Id = param.JobID task.Name = param.ExecutorHandler task.Param = param