|
@@ -1,6 +1,5 @@
|
1
|
1
|
package com.xxl.job.admin.core.callback;
|
2
|
2
|
|
3
|
|
-import com.xxl.job.admin.core.model.ReturnT;
|
4
|
3
|
import com.xxl.job.admin.core.model.XxlJobInfo;
|
5
|
4
|
import com.xxl.job.admin.core.model.XxlJobLog;
|
6
|
5
|
import com.xxl.job.admin.core.util.DynamicSchedulerUtil;
|
|
@@ -35,65 +34,80 @@ public class XxlJobLogCallbackServerHandler extends AbstractHandler {
|
35
|
34
|
|
36
|
35
|
// parse hex-json to request model
|
37
|
36
|
String requestHex = httpServletRequest.getParameter(XxlJobNetCommUtil.HEX);
|
|
37
|
+
|
|
38
|
+ // do biz
|
|
39
|
+ ResponseModel responseModel = dobiz(requestHex);
|
|
40
|
+
|
|
41
|
+ // format response model to hex-json
|
|
42
|
+ String responseHex = XxlJobNetCommUtil.formatObj2HexJson(responseModel);
|
|
43
|
+
|
|
44
|
+ // response
|
|
45
|
+ httpServletResponse.setContentType("text/html;charset=utf-8");
|
|
46
|
+ httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
|
47
|
+ baseRequest.setHandled(true);
|
|
48
|
+ httpServletResponse.getWriter().println(responseHex);
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ private ResponseModel dobiz(String requestHex){
|
|
52
|
+
|
|
53
|
+ // valid hex
|
|
54
|
+ if (requestHex==null || requestHex.trim().length()==0) {
|
|
55
|
+ return new ResponseModel(ResponseModel.FAIL, "request hex is null.");
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ // valid request model
|
38
|
59
|
RequestModel requestModel = XxlJobNetCommUtil.parseHexJson2Obj(requestHex, RequestModel.class);
|
|
60
|
+ if (requestModel==null) {
|
|
61
|
+ return new ResponseModel(ResponseModel.FAIL, "request hex parse fail.");
|
|
62
|
+ }
|
39
|
63
|
|
40
|
|
- // process
|
41
|
|
- ResponseModel responseModel = null;
|
|
64
|
+ // valid log item
|
42
|
65
|
XxlJobLog log = DynamicSchedulerUtil.xxlJobLogDao.load(requestModel.getLogId());
|
43
|
|
- if (log!=null) {
|
44
|
|
-
|
45
|
|
- // trigger success, to trigger child job, and avoid repeat trigger child job
|
46
|
|
- String childTriggerMsg = null;
|
47
|
|
- if (ResponseModel.SUCCESS.equals(requestModel.getStatus()) && !ResponseModel.SUCCESS.equals(log.getHandleStatus())) {
|
48
|
|
- XxlJobInfo xxlJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
|
49
|
|
- if (xxlJobInfo!=null && StringUtils.isNotBlank(xxlJobInfo.getChildJobKey())) {
|
50
|
|
- childTriggerMsg = "<hr>";
|
51
|
|
- String[] childJobKeys = xxlJobInfo.getChildJobKey().split(",");
|
52
|
|
- for (int i = 0; i < childJobKeys.length; i++) {
|
53
|
|
- String[] jobKeyArr = childJobKeys[i].split("_");
|
54
|
|
- if (jobKeyArr!=null && jobKeyArr.length==2) {
|
55
|
|
- XxlJobInfo childJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(jobKeyArr[0], jobKeyArr[1]);
|
56
|
|
- if (childJobInfo!=null) {
|
57
|
|
- try {
|
58
|
|
- boolean ret = DynamicSchedulerUtil.triggerJob(childJobInfo.getJobName(), childJobInfo.getJobGroup());
|
59
|
|
-
|
60
|
|
- // add msg
|
61
|
|
- childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务成功, 子任务Key: {2}, status: {3}, 子任务描述: {4}",
|
62
|
|
- (i+1), childJobKeys.length, childJobKeys[i], ret, childJobInfo.getJobDesc());
|
63
|
|
- } catch (SchedulerException e) {
|
64
|
|
- logger.error("", e);
|
65
|
|
- }
|
66
|
|
- } else {
|
67
|
|
- childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务失败, 子任务xxlJobInfo不存在, 子任务Key: {2}",
|
68
|
|
- (i+1), childJobKeys.length, childJobKeys[i]);
|
|
66
|
+ if (log == null) {
|
|
67
|
+ return new ResponseModel(ResponseModel.FAIL, "log item not found.");
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ // trigger success, to trigger child job, and avoid repeat trigger child job
|
|
71
|
+ String childTriggerMsg = null;
|
|
72
|
+ if (ResponseModel.SUCCESS.equals(requestModel.getStatus()) && !ResponseModel.SUCCESS.equals(log.getHandleStatus())) {
|
|
73
|
+ XxlJobInfo xxlJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
|
|
74
|
+ if (xxlJobInfo!=null && StringUtils.isNotBlank(xxlJobInfo.getChildJobKey())) {
|
|
75
|
+ childTriggerMsg = "<hr>";
|
|
76
|
+ String[] childJobKeys = xxlJobInfo.getChildJobKey().split(",");
|
|
77
|
+ for (int i = 0; i < childJobKeys.length; i++) {
|
|
78
|
+ String[] jobKeyArr = childJobKeys[i].split("_");
|
|
79
|
+ if (jobKeyArr!=null && jobKeyArr.length==2) {
|
|
80
|
+ XxlJobInfo childJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(jobKeyArr[0], jobKeyArr[1]);
|
|
81
|
+ if (childJobInfo!=null) {
|
|
82
|
+ try {
|
|
83
|
+ boolean ret = DynamicSchedulerUtil.triggerJob(childJobInfo.getJobName(), childJobInfo.getJobGroup());
|
|
84
|
+
|
|
85
|
+ // add msg
|
|
86
|
+ childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务成功, 子任务Key: {2}, status: {3}, 子任务描述: {4}",
|
|
87
|
+ (i+1), childJobKeys.length, childJobKeys[i], ret, childJobInfo.getJobDesc());
|
|
88
|
+ } catch (SchedulerException e) {
|
|
89
|
+ logger.error("", e);
|
69
|
90
|
}
|
70
|
91
|
} else {
|
71
|
|
- childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务失败, 子任务Key格式错误, 子任务Key: {2}",
|
|
92
|
+ childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务失败, 子任务xxlJobInfo不存在, 子任务Key: {2}",
|
72
|
93
|
(i+1), childJobKeys.length, childJobKeys[i]);
|
73
|
94
|
}
|
|
95
|
+ } else {
|
|
96
|
+ childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务失败, 子任务Key格式错误, 子任务Key: {2}",
|
|
97
|
+ (i+1), childJobKeys.length, childJobKeys[i]);
|
74
|
98
|
}
|
75
|
|
-
|
76
|
99
|
}
|
77
|
|
- }
|
78
|
100
|
|
79
|
|
- // save log
|
80
|
|
- log.setHandleTime(new Date());
|
81
|
|
- log.setHandleStatus(requestModel.getStatus());
|
82
|
|
- log.setHandleMsg(requestModel.getMsg() + childTriggerMsg);
|
83
|
|
- DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(log);
|
84
|
|
- responseModel = new ResponseModel(ResponseModel.SUCCESS, null);
|
85
|
|
- } else {
|
86
|
|
- responseModel = new ResponseModel(ResponseModel.FAIL, "log item not found.");
|
|
101
|
+ }
|
87
|
102
|
}
|
88
|
103
|
|
89
|
|
- // format response model to hex-json
|
90
|
|
- String responseHex = XxlJobNetCommUtil.formatObj2HexJson(responseModel);
|
|
104
|
+ // success, save log
|
|
105
|
+ log.setHandleTime(new Date());
|
|
106
|
+ log.setHandleStatus(requestModel.getStatus());
|
|
107
|
+ log.setHandleMsg(requestModel.getMsg() + childTriggerMsg);
|
|
108
|
+ DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(log);
|
91
|
109
|
|
92
|
|
- // response
|
93
|
|
- httpServletResponse.setContentType("text/html;charset=utf-8");
|
94
|
|
- httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
95
|
|
- baseRequest.setHandled(true);
|
96
|
|
- httpServletResponse.getWriter().println(responseHex);
|
|
110
|
+ return new ResponseModel(ResponseModel.SUCCESS, null);
|
97
|
111
|
}
|
98
|
112
|
|
99
|
113
|
}
|