|
@@ -13,12 +13,11 @@ import com.xxl.job.core.biz.model.TriggerParam;
|
13
|
13
|
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
14
|
14
|
import com.xxl.job.core.util.IpUtil;
|
15
|
15
|
import org.apache.commons.collections4.CollectionUtils;
|
|
16
|
+import org.apache.commons.lang3.StringUtils;
|
16
|
17
|
import org.slf4j.Logger;
|
17
|
18
|
import org.slf4j.LoggerFactory;
|
18
|
19
|
|
19
|
|
-import java.util.ArrayList;
|
20
|
20
|
import java.util.Date;
|
21
|
|
-import java.util.List;
|
22
|
21
|
|
23
|
22
|
/**
|
24
|
23
|
* xxl-job trigger
|
|
@@ -36,27 +35,38 @@ public class XxlJobTrigger {
|
36
|
35
|
* <0: use param from job info config
|
37
|
36
|
*
|
38
|
37
|
*/
|
39
|
|
- public static void trigger(int jobId, int failRetryCount, TriggerTypeEnum triggerType) {
|
|
38
|
+ public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam) {
|
40
|
39
|
// load data
|
41
|
|
- XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId); // job info
|
|
40
|
+ XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId);
|
42
|
41
|
if (jobInfo == null) {
|
43
|
42
|
logger.warn(">>>>>>>>>>>> trigger fail, jobId invalid,jobId={}", jobId);
|
44
|
43
|
return;
|
45
|
44
|
}
|
46
|
45
|
int finalFailRetryCount = failRetryCount>=0?failRetryCount:jobInfo.getExecutorFailRetryCount();
|
47
|
|
- XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup()); // group info
|
|
46
|
+ XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup());
|
48
|
47
|
|
49
|
48
|
// process trigger
|
50
|
|
- if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) && CollectionUtils.isNotEmpty(group.getRegistryList())) {
|
51
|
|
- for (int i = 0; i < group.getRegistryList().size(); i++) {
|
52
|
|
- processTrigger(group, jobInfo, finalFailRetryCount, triggerType, i);
|
|
49
|
+ if (triggerType==TriggerTypeEnum.RETRY && executorShardingParam!=null) {
|
|
50
|
+ String[] shardingArr = executorShardingParam.split("/");
|
|
51
|
+ if (shardingArr.length==2 && StringUtils.isNumeric(shardingArr[0]) && StringUtils.isNumeric(shardingArr[1])); {
|
|
52
|
+ processTrigger(group, jobInfo, finalFailRetryCount, triggerType, Integer.valueOf(shardingArr[0]), Integer.valueOf(shardingArr[1]));
|
53
|
53
|
}
|
54
|
54
|
} else {
|
55
|
|
- processTrigger(group, jobInfo, finalFailRetryCount, triggerType, 0);
|
|
55
|
+ if (CollectionUtils.isNotEmpty(group.getRegistryList())) {
|
|
56
|
+ if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null)) {
|
|
57
|
+ for (int i = 0; i < group.getRegistryList().size(); i++) {
|
|
58
|
+ processTrigger(group, jobInfo, finalFailRetryCount, triggerType, i, group.getRegistryList().size());
|
|
59
|
+ }
|
|
60
|
+ } else {
|
|
61
|
+ processTrigger(group, jobInfo, finalFailRetryCount, triggerType, 0, 1);
|
|
62
|
+ }
|
|
63
|
+ } else {
|
|
64
|
+ processTrigger(group, jobInfo, finalFailRetryCount, triggerType, 0, 0);
|
|
65
|
+ }
|
56
|
66
|
}
|
57
|
67
|
}
|
58
|
68
|
|
59
|
|
- private static void processTrigger(XxlJobGroup group, XxlJobInfo jobInfo, int finalFailRetryCount, TriggerTypeEnum triggerType, int index){
|
|
69
|
+ private static void processTrigger(XxlJobGroup group, XxlJobInfo jobInfo, int finalFailRetryCount, TriggerTypeEnum triggerType, int index, int total){
|
60
|
70
|
|
61
|
71
|
// param
|
62
|
72
|
ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION); // block strategy
|
|
@@ -83,11 +93,12 @@ public class XxlJobTrigger {
|
83
|
93
|
triggerParam.setGlueSource(jobInfo.getGlueSource());
|
84
|
94
|
triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
|
85
|
95
|
triggerParam.setBroadcastIndex(index);
|
86
|
|
- triggerParam.setBroadcastTotal(group.getRegistryList()!=null?group.getRegistryList().size():0);
|
|
96
|
+ triggerParam.setBroadcastTotal(total);
|
87
|
97
|
|
88
|
98
|
// 3、init address
|
89
|
99
|
String address = null;
|
90
|
100
|
ReturnT<String> routeAddressResult = null;
|
|
101
|
+ String shardingParam = (ExecutorRouteStrategyEnum.SHARDING_BROADCAST==executorRouteStrategyEnum &&total>0)?String.valueOf(triggerParam.getBroadcastIndex()).concat("/").concat(String.valueOf(triggerParam.getBroadcastTotal())):null;
|
91
|
102
|
if (CollectionUtils.isNotEmpty(group.getRegistryList())) {
|
92
|
103
|
if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) {
|
93
|
104
|
address = group.getRegistryList().get(index);
|
|
@@ -117,8 +128,8 @@ public class XxlJobTrigger {
|
117
|
128
|
.append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") );
|
118
|
129
|
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList());
|
119
|
130
|
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle());
|
120
|
|
- if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null)) {
|
121
|
|
- triggerMsgSb.append("("+index+"/"+(group.getRegistryList()!=null?group.getRegistryList().size():0)+")");
|
|
131
|
+ if (shardingParam != null) {
|
|
132
|
+ triggerMsgSb.append("("+shardingParam+")");
|
122
|
133
|
}
|
123
|
134
|
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle());
|
124
|
135
|
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout());
|
|
@@ -131,6 +142,7 @@ public class XxlJobTrigger {
|
131
|
142
|
jobLog.setExecutorAddress(address);
|
132
|
143
|
jobLog.setExecutorHandler(jobInfo.getExecutorHandler());
|
133
|
144
|
jobLog.setExecutorParam(jobInfo.getExecutorParam());
|
|
145
|
+ jobLog.setExecutorShardingParam(shardingParam);
|
134
|
146
|
jobLog.setExecutorFailRetryCount(finalFailRetryCount);
|
135
|
147
|
//jobLog.setTriggerTime();
|
136
|
148
|
jobLog.setTriggerCode(triggerResult.getCode());
|