Skip to content

Commit

Permalink
失败处理策略
Browse files Browse the repository at this point in the history
  • Loading branch information
xueli.xue committed May 9, 2017
1 parent 370c816 commit 8600f88
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xxl.job.admin.core.jobbean;

import com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog;
Expand Down Expand Up @@ -70,6 +71,15 @@ protected void executeInternal(JobExecutionContext context)
// do trigger
ReturnT<String> triggerResult = doTrigger(triggerParam, jobInfo, jobLog);

// fail retry
if (triggerResult.getCode()==ReturnT.FAIL_CODE &&
ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), null) == ExecutorFailStrategyEnum.FAIL_RETRY) {
ReturnT<String> retryTriggerResult = doTrigger(triggerParam, jobInfo, jobLog);

triggerResult.setCode(retryTriggerResult.getCode());
triggerResult.setMsg(triggerResult.getMsg() + "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>失败重试<<<<<<<<<<< </span><br><br>" +retryTriggerResult.getMsg());
}

// log part-2
jobLog.setTriggerCode(triggerResult.getCode());
jobLog.setTriggerMsg(triggerResult.getMsg());
Expand Down Expand Up @@ -97,7 +107,7 @@ public ReturnT<String> doTrigger(TriggerParam triggerParam, XxlJobInfo jobInfo,
}
triggerSb.append("<br>地址列表:").append(addressList!=null?addressList.toString():"");
if (CollectionUtils.isEmpty(addressList)) {
triggerSb.append("<hr>调度失败:").append("执行器地址为空");
triggerSb.append("<br>----------------------<br>").append("调度失败:").append("执行器地址为空");
return new ReturnT<String>(ReturnT.FAIL_CODE, triggerSb.toString());
}

Expand All @@ -107,15 +117,15 @@ public ReturnT<String> doTrigger(TriggerParam triggerParam, XxlJobInfo jobInfo,
jobLog.setExecutorAddress(address);

ReturnT<String> runResult = runExecutor(triggerParam, address);
triggerSb.append("<hr>").append(runResult.getMsg());
triggerSb.append("<br>----------------------<br>").append(runResult.getMsg());

return new ReturnT<String>(runResult.getCode(), triggerSb.toString());
} else {
// executor route strategy
ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null);
triggerSb.append("<br>路由策略:").append(executorRouteStrategyEnum!=null?(executorRouteStrategyEnum.name() + "-" + executorRouteStrategyEnum.getTitle()):null);
if (executorRouteStrategyEnum == null) {
triggerSb.append("<hr>调度失败:").append("执行器路由策略为空");
triggerSb.append("<br>----------------------<br>").append("调度失败:").append("执行器路由策略为空");
return new ReturnT<String>(ReturnT.FAIL_CODE, triggerSb.toString());
}

Expand All @@ -126,20 +136,20 @@ public ReturnT<String> doTrigger(TriggerParam triggerParam, XxlJobInfo jobInfo,

// run
ReturnT<String> runResult = runExecutor(triggerParam, address);
triggerSb.append("<hr>").append(runResult.getMsg());
triggerSb.append("<br>----------------------<br>").append(runResult.getMsg());

return new ReturnT<String>(runResult.getCode(), triggerSb.toString());
} else {
for (String address : addressList) {
// beat
ReturnT<String> beatResult = beatExecutor(address);
triggerSb.append("<hr>").append(beatResult.getMsg());
triggerSb.append("<br>----------------------<br>").append(beatResult.getMsg());

if (beatResult.getCode() == ReturnT.SUCCESS_CODE) {
jobLog.setExecutorAddress(address);

ReturnT<String> runResult = runExecutor(triggerParam, address);
triggerSb.append("<hr>").append(runResult.getMsg());
triggerSb.append("<br>----------------------<br>").append(runResult.getMsg());

return new ReturnT<String>(runResult.getCode(), triggerSb.toString());
}
Expand Down

0 comments on commit 8600f88

Please sign in to comment.