|
|
|
@ -13,6 +13,7 @@ import com.xxl.job.core.biz.AdminBiz;
|
|
|
|
|
import com.xxl.job.core.biz.model.HandleCallbackParam;
|
|
|
|
|
import com.xxl.job.core.biz.model.RegistryParam;
|
|
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
|
import com.xxl.job.core.handler.IJobHandler;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.quartz.SchedulerException;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
@ -46,7 +47,7 @@ public class AdminBizImpl implements AdminBiz {
|
|
|
|
|
for (HandleCallbackParam handleCallbackParam: callbackParamList) {
|
|
|
|
|
ReturnT<String> callbackResult = callback(handleCallbackParam);
|
|
|
|
|
logger.info(">>>>>>>>> JobApiController.callback {}, handleCallbackParam={}, callbackResult={}",
|
|
|
|
|
(callbackResult.getCode()==ReturnT.SUCCESS_CODE?"success":"fail"), handleCallbackParam, callbackResult);
|
|
|
|
|
(callbackResult.getCode()==IJobHandler.SUCCESS.getCode()?"success":"fail"), handleCallbackParam, callbackResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
@ -58,28 +59,39 @@ public class AdminBizImpl implements AdminBiz {
|
|
|
|
|
if (log == null) {
|
|
|
|
|
return new ReturnT<String>(ReturnT.FAIL_CODE, "log item not found.");
|
|
|
|
|
}
|
|
|
|
|
if (log.getHandleCode() > 0) {
|
|
|
|
|
return new ReturnT<String>(ReturnT.FAIL_CODE, "log repeate callback."); // avoid repeat callback, trigger child job etc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// trigger success, to trigger child job, and avoid repeat trigger child job
|
|
|
|
|
String childTriggerMsg = null;
|
|
|
|
|
if (ReturnT.SUCCESS_CODE==handleCallbackParam.getExecuteResult().getCode() && ReturnT.SUCCESS_CODE!=log.getHandleCode()) {
|
|
|
|
|
// trigger success, to trigger child job
|
|
|
|
|
String callbackMsg = null;
|
|
|
|
|
if (IJobHandler.SUCCESS.getCode() == handleCallbackParam.getExecuteResult().getCode()) {
|
|
|
|
|
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(log.getJobId());
|
|
|
|
|
if (xxlJobInfo!=null && StringUtils.isNotBlank(xxlJobInfo.getChildJobKey())) {
|
|
|
|
|
childTriggerMsg = "<hr>";
|
|
|
|
|
callbackMsg = "<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>触发子任务<<<<<<<<<<< </span><br>";
|
|
|
|
|
|
|
|
|
|
String[] childJobKeys = xxlJobInfo.getChildJobKey().split(",");
|
|
|
|
|
for (int i = 0; i < childJobKeys.length; i++) {
|
|
|
|
|
String[] jobKeyArr = childJobKeys[i].split("_");
|
|
|
|
|
if (jobKeyArr!=null && jobKeyArr.length==2) {
|
|
|
|
|
ReturnT<String> triggerChildResult = xxlJobService.triggerJob(Integer.valueOf(jobKeyArr[1]));
|
|
|
|
|
|
|
|
|
|
// add msg
|
|
|
|
|
childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务{2}, 子任务Key: {3}, 子任务触发备注: {4}",
|
|
|
|
|
(i+1), childJobKeys.length, (triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?"成功":"失败"), childJobKeys[i], triggerChildResult.getMsg());
|
|
|
|
|
callbackMsg += MessageFormat.format("{0}/{1} [JobKey={2}], 触发{3}, 触发备注: {4} <br>",
|
|
|
|
|
(i+1), childJobKeys.length, childJobKeys[i], (triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?"成功":"失败"), triggerChildResult.getMsg());
|
|
|
|
|
} else {
|
|
|
|
|
childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务失败, 子任务Key格式错误, 子任务Key: {2}",
|
|
|
|
|
callbackMsg += MessageFormat.format(" {0}/{1} [JobKey={2}], 触发失败, 触发备注: JobKey格式错误 <br>",
|
|
|
|
|
(i+1), childJobKeys.length, childJobKeys[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else if (IJobHandler.FAIL_RETRY.getCode() == handleCallbackParam.getExecuteResult().getCode()){
|
|
|
|
|
ReturnT<String> retryTriggerResult = xxlJobService.triggerJob(log.getJobId());
|
|
|
|
|
callbackMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>执行失败重试<<<<<<<<<<< </span><br>";
|
|
|
|
|
|
|
|
|
|
callbackMsg += MessageFormat.format("触发{0}, 触发备注: {1}",
|
|
|
|
|
(retryTriggerResult.getCode()==ReturnT.SUCCESS_CODE?"成功":"失败"), retryTriggerResult.getMsg());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handle msg
|
|
|
|
@ -90,8 +102,8 @@ public class AdminBizImpl implements AdminBiz {
|
|
|
|
|
if (handleCallbackParam.getExecuteResult().getMsg() != null) {
|
|
|
|
|
handleMsg.append(handleCallbackParam.getExecuteResult().getMsg());
|
|
|
|
|
}
|
|
|
|
|
if (childTriggerMsg !=null) {
|
|
|
|
|
handleMsg.append("<br>子任务触发备注:").append(childTriggerMsg);
|
|
|
|
|
if (callbackMsg != null) {
|
|
|
|
|
handleMsg.append(callbackMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// success, save log
|
|
|
|
|