fix:修复httpjob循环调用bug

This commit is contained in:
zhangwenjian
2020-10-13 22:19:59 +08:00
parent 3b5ce7ffaf
commit d1d545b29c
+13 -5
View File
@@ -44,7 +44,11 @@ func (e *ExecJob) Run() {
global.JobLogger.Warning(" ExecJob Run job nil", e) global.JobLogger.Warning(" ExecJob Run job nil", e)
return return
} }
CallExec(obj.(JobsExec), e.Args) err := CallExec(obj.(JobsExec), e.Args)
if err != nil {
// 如果失败暂停一段时间重试
fmt.Println(time.Now().Format(timeFormat), " [ERROR] mission failed! ", err)
}
// 结束时间 // 结束时间
endTime := time.Now() endTime := time.Now()
@@ -54,6 +58,7 @@ func (e *ExecJob) Run() {
//str := time.Now().Format(timeFormat) + " [INFO] JobCore " + string(e.EntryId) + "exec success , spend :" + latencyTime.String() //str := time.Now().Format(timeFormat) + " [INFO] JobCore " + string(e.EntryId) + "exec success , spend :" + latencyTime.String()
//ws.SendAll(str) //ws.SendAll(str)
global.JobLogger.Info(time.Now().Format(timeFormat), " [INFO] JobCore ", e, "exec success , spend :", latencyTime) global.JobLogger.Info(time.Now().Format(timeFormat), " [INFO] JobCore ", e, "exec success , spend :", latencyTime)
return
} }
//http 任务接口 //http 任务接口
@@ -61,19 +66,21 @@ func (h *HttpJob) Run() {
startTime := time.Now() startTime := time.Now()
var count = 0 var count = 0
var err error
var str string
/* 循环 */ /* 循环 */
LOOP: LOOP:
if count < retryCount { if count < retryCount {
/* 跳过迭代 */ /* 跳过迭代 */
str, err := pkg.Get(h.InvokeTarget) str, err = pkg.Get(h.InvokeTarget)
if err != nil { if err != nil {
// 如果失败暂停一段时间重试 // 如果失败暂停一段时间重试
fmt.Println(time.Now().Format(timeFormat), " [ERROR] mission failed! ", err) fmt.Println(time.Now().Format(timeFormat), " [ERROR] mission failed! ", err)
fmt.Printf(time.Now().Format(timeFormat)+" [INFO] Retry after the task fails %d seconds! %s \n", time.Duration(count)*time.Second, str) fmt.Printf(time.Now().Format(timeFormat)+" [INFO] Retry after the task fails %d seconds! %s \n", (count+1)*5, str)
time.Sleep(time.Duration(count) * time.Second) time.Sleep(time.Duration(count+1) * 5 * time.Second)
count = count + 1
goto LOOP goto LOOP
} }
count = count + 1
} }
// 结束时间 // 结束时间
endTime := time.Now() endTime := time.Now()
@@ -83,6 +90,7 @@ LOOP:
//TODO: 待完善部分 //TODO: 待完善部分
global.JobLogger.Info(time.Now().Format(timeFormat), " [INFO] JobCore ", h, "exec success , spend :", latencyTime) global.JobLogger.Info(time.Now().Format(timeFormat), " [INFO] JobCore ", h, "exec success , spend :", latencyTime)
return
} }
// 初始化 // 初始化