|
|
@@ -13,6 +13,7 @@ import com.xxl.job.core.biz.AdminBiz;
|
|
13
|
13
|
import com.xxl.job.core.biz.model.HandleCallbackParam;
|
|
14
|
14
|
import com.xxl.job.core.biz.model.RegistryParam;
|
|
15
|
15
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
16
|
+import com.xxl.job.core.handler.IJobHandler;
|
|
16
|
17
|
import org.apache.commons.lang.StringUtils;
|
|
17
|
18
|
import org.quartz.SchedulerException;
|
|
18
|
19
|
import org.slf4j.Logger;
|
|
|
@@ -46,7 +47,7 @@ public class AdminBizImpl implements AdminBiz {
|
|
46
|
47
|
for (HandleCallbackParam handleCallbackParam: callbackParamList) {
|
|
47
|
48
|
ReturnT<String> callbackResult = callback(handleCallbackParam);
|
|
48
|
49
|
logger.info(">>>>>>>>> JobApiController.callback {}, handleCallbackParam={}, callbackResult={}",
|
|
49
|
|
- (callbackResult.getCode()==ReturnT.SUCCESS_CODE?"success":"fail"), handleCallbackParam, callbackResult);
|
|
|
50
|
+ (callbackResult.getCode()==IJobHandler.SUCCESS.getCode()?"success":"fail"), handleCallbackParam, callbackResult);
|
|
50
|
51
|
}
|
|
51
|
52
|
|
|
52
|
53
|
return ReturnT.SUCCESS;
|
|
|
@@ -58,28 +59,39 @@ public class AdminBizImpl implements AdminBiz {
|
|
58
|
59
|
if (log == null) {
|
|
59
|
60
|
return new ReturnT<String>(ReturnT.FAIL_CODE, "log item not found.");
|
|
60
|
61
|
}
|
|
|
62
|
+ if (log.getHandleCode() > 0) {
|
|
|
63
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "log repeate callback."); // avoid repeat callback, trigger child job etc
|
|
|
64
|
+ }
|
|
61
|
65
|
|
|
62
|
|
- // trigger success, to trigger child job, and avoid repeat trigger child job
|
|
63
|
|
- String childTriggerMsg = null;
|
|
64
|
|
- if (ReturnT.SUCCESS_CODE==handleCallbackParam.getExecuteResult().getCode() && ReturnT.SUCCESS_CODE!=log.getHandleCode()) {
|
|
|
66
|
+ // trigger success, to trigger child job
|
|
|
67
|
+ String callbackMsg = null;
|
|
|
68
|
+ if (IJobHandler.SUCCESS.getCode() == handleCallbackParam.getExecuteResult().getCode()) {
|
|
65
|
69
|
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(log.getJobId());
|
|
66
|
70
|
if (xxlJobInfo!=null && StringUtils.isNotBlank(xxlJobInfo.getChildJobKey())) {
|
|
67
|
|
- childTriggerMsg = "<hr>";
|
|
|
71
|
+ callbackMsg = "<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>触发子任务<<<<<<<<<<< </span><br>";
|
|
|
72
|
+
|
|
68
|
73
|
String[] childJobKeys = xxlJobInfo.getChildJobKey().split(",");
|
|
69
|
74
|
for (int i = 0; i < childJobKeys.length; i++) {
|
|
70
|
75
|
String[] jobKeyArr = childJobKeys[i].split("_");
|
|
71
|
76
|
if (jobKeyArr!=null && jobKeyArr.length==2) {
|
|
72
|
77
|
ReturnT<String> triggerChildResult = xxlJobService.triggerJob(Integer.valueOf(jobKeyArr[1]));
|
|
|
78
|
+
|
|
73
|
79
|
// add msg
|
|
74
|
|
- childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务{2}, 子任务Key: {3}, 子任务触发备注: {4}",
|
|
75
|
|
- (i+1), childJobKeys.length, (triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?"成功":"失败"), childJobKeys[i], triggerChildResult.getMsg());
|
|
|
80
|
+ callbackMsg += MessageFormat.format("{0}/{1} [JobKey={2}], 触发{3}, 触发备注: {4} <br>",
|
|
|
81
|
+ (i+1), childJobKeys.length, childJobKeys[i], (triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?"成功":"失败"), triggerChildResult.getMsg());
|
|
76
|
82
|
} else {
|
|
77
|
|
- childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务失败, 子任务Key格式错误, 子任务Key: {2}",
|
|
|
83
|
+ callbackMsg += MessageFormat.format(" {0}/{1} [JobKey={2}], 触发失败, 触发备注: JobKey格式错误 <br>",
|
|
78
|
84
|
(i+1), childJobKeys.length, childJobKeys[i]);
|
|
79
|
85
|
}
|
|
80
|
86
|
}
|
|
81
|
87
|
|
|
82
|
88
|
}
|
|
|
89
|
+ } else if (IJobHandler.FAIL_RETRY.getCode() == handleCallbackParam.getExecuteResult().getCode()){
|
|
|
90
|
+ ReturnT<String> retryTriggerResult = xxlJobService.triggerJob(log.getJobId());
|
|
|
91
|
+ callbackMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>执行失败重试<<<<<<<<<<< </span><br>";
|
|
|
92
|
+
|
|
|
93
|
+ callbackMsg += MessageFormat.format("触发{0}, 触发备注: {1}",
|
|
|
94
|
+ (retryTriggerResult.getCode()==ReturnT.SUCCESS_CODE?"成功":"失败"), retryTriggerResult.getMsg());
|
|
83
|
95
|
}
|
|
84
|
96
|
|
|
85
|
97
|
// handle msg
|
|
|
@@ -90,8 +102,8 @@ public class AdminBizImpl implements AdminBiz {
|
|
90
|
102
|
if (handleCallbackParam.getExecuteResult().getMsg() != null) {
|
|
91
|
103
|
handleMsg.append(handleCallbackParam.getExecuteResult().getMsg());
|
|
92
|
104
|
}
|
|
93
|
|
- if (childTriggerMsg !=null) {
|
|
94
|
|
- handleMsg.append("<br>子任务触发备注:").append(childTriggerMsg);
|
|
|
105
|
+ if (callbackMsg != null) {
|
|
|
106
|
+ handleMsg.append(callbackMsg);
|
|
95
|
107
|
}
|
|
96
|
108
|
|
|
97
|
109
|
// success, save log
|