dongyukun
2024-12-31 0a2b23ad3f30dfb01c5d590fb98f39e93bfe1932
提交 | 用户 | 时间
e7c126 1 package com.xxl.job.admin.core.route.strategy;
H 2
3 import com.xxl.job.admin.core.scheduler.XxlJobScheduler;
4 import com.xxl.job.admin.core.route.ExecutorRouter;
5 import com.xxl.job.admin.core.util.I18nUtil;
6 import com.xxl.job.core.biz.ExecutorBiz;
7 import com.xxl.job.core.biz.model.IdleBeatParam;
8 import com.xxl.job.core.biz.model.ReturnT;
9 import com.xxl.job.core.biz.model.TriggerParam;
10
11 import java.util.List;
12
13 /**
14  * Created by xuxueli on 17/3/10.
15  */
16 public class ExecutorRouteBusyover extends ExecutorRouter {
17
18     @Override
19     public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) {
20         StringBuffer idleBeatResultSB = new StringBuffer();
21         for (String address : addressList) {
22             // beat
23             ReturnT<String> idleBeatResult = null;
24             try {
25                 ExecutorBiz executorBiz = XxlJobScheduler.getExecutorBiz(address);
26                 idleBeatResult = executorBiz.idleBeat(new IdleBeatParam(triggerParam.getJobId()));
27             } catch (Exception e) {
28                 logger.error(e.getMessage(), e);
29                 idleBeatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e );
30             }
31             idleBeatResultSB.append( (idleBeatResultSB.length()>0)?"<br><br>":"")
32                     .append(I18nUtil.getString("jobconf_idleBeat") + ":")
33                     .append("<br>address:").append(address)
34                     .append("<br>code:").append(idleBeatResult.getCode())
35                     .append("<br>msg:").append(idleBeatResult.getMsg());
36
37             // beat success
38             if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) {
39                 idleBeatResult.setMsg(idleBeatResultSB.toString());
40                 idleBeatResult.setContent(address);
41                 return idleBeatResult;
42             }
43         }
44
45         return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
46     }
47
48 }