提交 | 用户 | 时间
|
e7c126
|
1 |
package com.xxl.job.admin.core.complete; |
H |
2 |
|
|
3 |
import com.xxl.job.admin.core.conf.XxlJobAdminConfig; |
|
4 |
import com.xxl.job.admin.core.model.XxlJobInfo; |
|
5 |
import com.xxl.job.admin.core.model.XxlJobLog; |
|
6 |
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; |
|
7 |
import com.xxl.job.admin.core.trigger.TriggerTypeEnum; |
|
8 |
import com.xxl.job.admin.core.util.I18nUtil; |
|
9 |
import com.xxl.job.core.biz.model.ReturnT; |
|
10 |
import com.xxl.job.core.context.XxlJobContext; |
|
11 |
import org.slf4j.Logger; |
|
12 |
import org.slf4j.LoggerFactory; |
|
13 |
|
|
14 |
import java.text.MessageFormat; |
|
15 |
|
|
16 |
/** |
|
17 |
* @author xuxueli 2020-10-30 20:43:10 |
|
18 |
*/ |
|
19 |
public class XxlJobCompleter { |
|
20 |
private static Logger logger = LoggerFactory.getLogger(XxlJobCompleter.class); |
|
21 |
|
|
22 |
/** |
|
23 |
* common fresh handle entrance (limit only once) |
|
24 |
* |
|
25 |
* @param xxlJobLog |
|
26 |
* @return |
|
27 |
*/ |
|
28 |
public static int updateHandleInfoAndFinish(XxlJobLog xxlJobLog) { |
|
29 |
|
|
30 |
// finish |
|
31 |
finishJob(xxlJobLog); |
|
32 |
|
|
33 |
// text最大64kb 避免长度过长 |
|
34 |
if (xxlJobLog.getHandleMsg().length() > 15000) { |
|
35 |
xxlJobLog.setHandleMsg( xxlJobLog.getHandleMsg().substring(0, 15000) ); |
|
36 |
} |
|
37 |
|
|
38 |
// fresh handle |
|
39 |
return XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateHandleInfo(xxlJobLog); |
|
40 |
} |
|
41 |
|
|
42 |
|
|
43 |
/** |
|
44 |
* do somethind to finish job |
|
45 |
*/ |
|
46 |
private static void finishJob(XxlJobLog xxlJobLog){ |
|
47 |
|
|
48 |
// 1、handle success, to trigger child job |
|
49 |
String triggerChildMsg = null; |
|
50 |
if (XxlJobContext.HANDLE_CODE_SUCCESS == xxlJobLog.getHandleCode()) { |
|
51 |
XxlJobInfo xxlJobInfo = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(xxlJobLog.getJobId()); |
|
52 |
if (xxlJobInfo!=null && xxlJobInfo.getChildJobId()!=null && xxlJobInfo.getChildJobId().trim().length()>0) { |
|
53 |
triggerChildMsg = "<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_child_run") +"<<<<<<<<<<< </span><br>"; |
|
54 |
|
|
55 |
String[] childJobIds = xxlJobInfo.getChildJobId().split(","); |
|
56 |
for (int i = 0; i < childJobIds.length; i++) { |
|
57 |
int childJobId = (childJobIds[i]!=null && childJobIds[i].trim().length()>0 && isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1; |
|
58 |
if (childJobId > 0) { |
|
59 |
|
|
60 |
JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null, null); |
|
61 |
ReturnT<String> triggerChildResult = ReturnT.SUCCESS; |
|
62 |
|
|
63 |
// add msg |
|
64 |
triggerChildMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg1"), |
|
65 |
(i+1), |
|
66 |
childJobIds.length, |
|
67 |
childJobIds[i], |
|
68 |
(triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?I18nUtil.getString("system_success"):I18nUtil.getString("system_fail")), |
|
69 |
triggerChildResult.getMsg()); |
|
70 |
} else { |
|
71 |
triggerChildMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg2"), |
|
72 |
(i+1), |
|
73 |
childJobIds.length, |
|
74 |
childJobIds[i]); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
if (triggerChildMsg != null) { |
|
82 |
xxlJobLog.setHandleMsg( xxlJobLog.getHandleMsg() + triggerChildMsg ); |
|
83 |
} |
|
84 |
|
|
85 |
// 2、fix_delay trigger next |
|
86 |
// on the way |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
private static boolean isNumeric(String str){ |
|
91 |
try { |
|
92 |
int result = Integer.valueOf(str); |
|
93 |
return true; |
|
94 |
} catch (NumberFormatException e) { |
|
95 |
return false; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
} |