失败策略优化

pull/MERGE
xuxueli 7 years ago
parent 399cc2b1a7
commit d0c4c3f07a

@ -7,9 +7,11 @@ import com.xxl.job.admin.core.util.I18nUtil;
*/ */
public enum ExecutorFailStrategyEnum { public enum ExecutorFailStrategyEnum {
FAIL_ALARM(I18nUtil.getString("jobconf_fail_alarm")), NULL(I18nUtil.getString("jobconf_fail_null")),
FAIL_RETRY(I18nUtil.getString("jobconf_fail_retry")); FAIL_TRIGGER_RETRY(I18nUtil.getString("jobconf_fail_trigger_retry")),
FAIL_HANDLE_RETRY(I18nUtil.getString("jobconf_fail_handle_retry"));
private final String title; private final String title;
private ExecutorFailStrategyEnum(String title) { private ExecutorFailStrategyEnum(String title) {

@ -43,7 +43,7 @@ public class XxlJobTrigger {
XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup()); // group info XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup()); // group info
ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION); // block strategy ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION); // block strategy
ExecutorFailStrategyEnum failStrategy = ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), ExecutorFailStrategyEnum.FAIL_ALARM); // fail strategy ExecutorFailStrategyEnum failStrategy = ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), ExecutorFailStrategyEnum.NULL); // fail strategy
ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null); // route strategy ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null); // route strategy
ArrayList<String> addressList = (ArrayList<String>) group.getRegistryList(); ArrayList<String> addressList = (ArrayList<String>) group.getRegistryList();
@ -104,9 +104,9 @@ public class XxlJobTrigger {
triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg()); triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
// 4.3、trigger (fail retry) // 4.3、trigger (fail retry)
if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_RETRY) { if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_TRIGGER_RETRY) {
triggerResult = runExecutor(triggerParam, address); // update04 triggerResult = runExecutor(triggerParam, address); // update04
triggerMsgSb.append("<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_fail_retry") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg()); triggerMsgSb.append("<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_fail_trigger_retry") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
} }
} }
@ -174,9 +174,9 @@ public class XxlJobTrigger {
triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg()); triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
// 4.3、trigger (fail retry) // 4.3、trigger (fail retry)
if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_RETRY) { if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_TRIGGER_RETRY) {
triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList); triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList);
triggerMsgSb.append("<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_fail_retry") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg()); triggerMsgSb.append("<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_fail_trigger_retry") +"<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
} }
} }

@ -1,5 +1,6 @@
package com.xxl.job.admin.service.impl; package com.xxl.job.admin.service.impl;
import com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum;
import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog; import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.core.util.I18nUtil;
@ -89,13 +90,24 @@ public class AdminBizImpl implements AdminBiz {
} }
} }
} else if (IJobHandler.FAIL_RETRY.getCode() == handleCallbackParam.getExecuteResult().getCode()){ } else {
boolean ifHandleRetry = false;
if (IJobHandler.FAIL_RETRY.getCode() == handleCallbackParam.getExecuteResult().getCode()) {
ifHandleRetry = true;
} else {
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(log.getJobId());
if (ExecutorFailStrategyEnum.FAIL_HANDLE_RETRY.name().equals(xxlJobInfo.getExecutorFailStrategy())) {
ifHandleRetry = true;
}
}
if (ifHandleRetry){
ReturnT<String> retryTriggerResult = xxlJobService.triggerJob(log.getJobId()); ReturnT<String> retryTriggerResult = xxlJobService.triggerJob(log.getJobId());
callbackMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_exe_fail_retry") +"<<<<<<<<<<< </span><br>"; callbackMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_fail_handle_retry") +"<<<<<<<<<<< </span><br>";
callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_msg1"), callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_msg1"),
(retryTriggerResult.getCode()==ReturnT.SUCCESS_CODE?I18nUtil.getString("system_success"):I18nUtil.getString("system_fail")), retryTriggerResult.getMsg()); (retryTriggerResult.getCode()==ReturnT.SUCCESS_CODE?I18nUtil.getString("system_success"):I18nUtil.getString("system_fail")), retryTriggerResult.getMsg());
} }
}
// handle msg // handle msg
StringBuffer handleMsg = new StringBuffer(); StringBuffer handleMsg = new StringBuffer();

@ -198,8 +198,9 @@ jobgroup_del_limit_1=拒绝删除, 系统至少保留一个执行器
jobconf_block_SERIAL_EXECUTION=单机串行 jobconf_block_SERIAL_EXECUTION=单机串行
jobconf_block_DISCARD_LATER=丢弃后续调度 jobconf_block_DISCARD_LATER=丢弃后续调度
jobconf_block_COVER_EARLY=覆盖之前调度 jobconf_block_COVER_EARLY=覆盖之前调度
jobconf_fail_alarm=失败告警 jobconf_fail_null=
jobconf_fail_retry=失败重试 jobconf_fail_trigger_retry=调度失败重试
jobconf_fail_handle_retry=执行失败重试
jobconf_route_first=第一个 jobconf_route_first=第一个
jobconf_route_last=最后一个 jobconf_route_last=最后一个
jobconf_route_round=轮询 jobconf_route_round=轮询
@ -223,8 +224,6 @@ jobconf_trigger_exe_regaddress=执行器-地址列表
jobconf_trigger_address_empty=调度失败:执行器地址为空 jobconf_trigger_address_empty=调度失败:执行器地址为空
jobconf_trigger_run=触发调度 jobconf_trigger_run=触发调度
jobconf_trigger_child_run=触发子任务 jobconf_trigger_child_run=触发子任务
jobconf_trigger_fail_retry=调度失败重试
jobconf_exe_fail_retry=执行失败重试
jobconf_callback_child_msg1={0}/{1} [任务ID={2}], 触发{3}, 触发备注: {4} <br> jobconf_callback_child_msg1={0}/{1} [任务ID={2}], 触发{3}, 触发备注: {4} <br>
jobconf_callback_child_msg2={0}/{1} [任务ID={2}], 触发失败, 触发备注: 任务ID格式错误 <br> jobconf_callback_child_msg2={0}/{1} [任务ID={2}], 触发失败, 触发备注: 任务ID格式错误 <br>
jobconf_callback_msg1=触发{0}, 触发备注: {1} <br> jobconf_callback_msg1=触发{0}, 触发备注: {1} <br>

@ -198,8 +198,9 @@ jobgroup_del_limit_1=Refuses to delete, the system retains at least one executor
jobconf_block_SERIAL_EXECUTION=Serial execution jobconf_block_SERIAL_EXECUTION=Serial execution
jobconf_block_DISCARD_LATER=Discard Later jobconf_block_DISCARD_LATER=Discard Later
jobconf_block_COVER_EARLY=Cover Early jobconf_block_COVER_EARLY=Cover Early
jobconf_fail_alarm=Fail Alarm jobconf_fail_null=Fail Alarm
jobconf_fail_retry=Fail Retry jobconf_fail_trigger_retry=Trigger Fail Retry
jobconf_fail_handle_retry=Handle Fail Retry
jobconf_route_first=First jobconf_route_first=First
jobconf_route_last=Last jobconf_route_last=Last
jobconf_route_round=Round jobconf_route_round=Round
@ -223,8 +224,6 @@ jobconf_trigger_exe_regaddress=Execotor-Registry Address
jobconf_trigger_address_empty=Trigger Failregistry address is empty jobconf_trigger_address_empty=Trigger Failregistry address is empty
jobconf_trigger_run=Trigger Job jobconf_trigger_run=Trigger Job
jobconf_trigger_child_run=Trigger child job jobconf_trigger_child_run=Trigger child job
jobconf_trigger_fail_retry=Trigger fail retry
jobconf_exe_fail_retry=Handle fail retry
jobconf_callback_child_msg1={0}/{1} [Job ID={2}], Trigger {3}, Trigger msg: {4} <br> jobconf_callback_child_msg1={0}/{1} [Job ID={2}], Trigger {3}, Trigger msg: {4} <br>
jobconf_callback_child_msg2={0}/{1} [Job ID={2}], Trigger Fail, Trigger msg: Job ID is illegal <br> jobconf_callback_child_msg2={0}/{1} [Job ID={2}], Trigger Fail, Trigger msg: Job ID is illegal <br>
jobconf_callback_msg1=Trigger {0}, Trigger msg: {1} <br> jobconf_callback_msg1=Trigger {0}, Trigger msg: {1} <br>

Loading…
Cancel
Save