Skip to content

Commit

Permalink
add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rushuinet committed Sep 9, 2020
1 parent f7b10c1 commit 0df3fe6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
4.任务panic处理
5.阻塞策略处理
6.任务完成支持返回执行备注
7.任务超时取消 (单位:秒,0为不限制)
8.失败重试次数(在参数param中,目前由任务自行处理)
9.日志查看(未完成)
```

## Example
Expand Down
8 changes: 6 additions & 2 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0df3fe6

Please sign in to comment.