From c8b9403e83ebabb9c24f68477fe122af00f412f4 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Fri, 22 Jul 2016 22:40:03 +0800 Subject: [PATCH] coding --- .../admin/controller/JobLogController.java | 2 +- .../src/main/resources/config.properties | 2 +- .../main/webapp/static/js/joblog.index.1.js | 2 +- .../xxl/job/core/router/HandlerRouter.java | 8 +++--- .../xxl/job/core/router/action/RunAction.java | 26 ++++++++++++------- .../xxl/job/core/router/thread/JobThread.java | 14 ++++------ .../router/thread/TriggerCallbackThread.java | 1 + 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java index 2a08c31a..ca2ed3fe 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java @@ -110,7 +110,7 @@ public class JobLogController { if (log == null) { return new ReturnT(500, "参数异常"); } - if (!ResponseModel.SUCCESS.equals(log.getTriggerStatus())) { + if (!(ResponseModel.SUCCESS.equals(log.getTriggerStatus()) || StringUtils.isNotBlank(log.getHandleStatus()))) { return new ReturnT(500, "调度失败,无法查看执行日志"); } diff --git a/xxl-job-admin/src/main/resources/config.properties b/xxl-job-admin/src/main/resources/config.properties index 703b34e4..2c1b490c 100644 --- a/xxl-job-admin/src/main/resources/config.properties +++ b/xxl-job-admin/src/main/resources/config.properties @@ -4,7 +4,7 @@ mail.port=25 mail.username=ovono802302@163.com mail.password=asdfzxcv mail.sendFrom=ovono802302@163.com -mail.sendNick=《调度平台平台XXL-JOB》 +mail.sendNick=《调度调度平台XXL-JOB》 # for login login.username=admin diff --git a/xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js b/xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js index 1f982b51..b98ffa27 100644 --- a/xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js +++ b/xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js @@ -130,7 +130,7 @@ $(function() { "render": function ( data, type, row ) { // better support expression or string, not function return function () { - if (row.triggerStatus == 'SUCCESS'){ + if (row.triggerStatus == 'SUCCESS' || row.handleStatus){ var temp = '执行日志'; if(!row.handleStatus){ temp += '
终止任务'; diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/router/HandlerRouter.java b/xxl-job-core/src/main/java/com/xxl/job/core/router/HandlerRouter.java index b1b366d9..95057249 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/router/HandlerRouter.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/router/HandlerRouter.java @@ -37,10 +37,10 @@ public class HandlerRouter { */ private static ConcurrentHashMap JobThreadRepository = new ConcurrentHashMap(); public static JobThread registJobThread(String jobkey, IJobHandler handler){ - JobThread handlerThread = new JobThread(handler); - handlerThread.start(); - logger.info(">>>>>>>>>>> xxl-job regist handler success, jobkey:{}, handler:{}", new Object[]{jobkey, handler}); - return HandlerRouter.JobThreadRepository.put(jobkey, handlerThread); // putIfAbsent + JobThread jobThread = new JobThread(handler); + jobThread.start(); + logger.info(">>>>>>>>>>> xxl-job regist JobThread success, jobkey:{}, handler:{}", new Object[]{jobkey, handler}); + return HandlerRouter.JobThreadRepository.put(jobkey, jobThread); // putIfAbsent } public static JobThread loadJobThread(String jobKey){ return HandlerRouter.JobThreadRepository.get(jobKey); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java b/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java index 7fea5bae..93d5b374 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java @@ -27,20 +27,17 @@ public class RunAction extends IAction { // handler instance IJobHandler jobHandler = HandlerRouter.loadJobHandler(requestModel.getExecutorHandler()); + if (jobHandler==null) { + return new ResponseModel(ResponseModel.FAIL, "job handler for jobKey=[" + jobKey + "] not found."); + } if (jobThread == null) { - // jobhandler match - if (jobHandler==null) { - return new ResponseModel(ResponseModel.FAIL, "job handler for jobKey=[" + jobKey + "] not found."); - } jobThread = HandlerRouter.registJobThread(jobKey, jobHandler); } else { - // job handler update, kill old job thread if (jobThread.getHandler() != jobHandler) { - // kill old job thread - jobThread.toStop("人工手动终止"); + jobThread.toStop("更换任务模式或JobHandler,终止旧任务线程"); jobThread.interrupt(); // new thread, with new job handler @@ -49,14 +46,25 @@ public class RunAction extends IAction { } } else { // glue model - if (jobThread == null) { jobThread = HandlerRouter.registJobThread(jobKey, new GlueJobHandler(requestModel.getJobGroup(), requestModel.getJobName())); + } else { + // job handler update, kill old job thread + if (!(jobThread.getHandler() instanceof GlueJobHandler)) { + // kill old job thread + jobThread.toStop("更换任务模式或JobHandler,终止旧任务线程"); + jobThread.interrupt(); + + // new thread, with new job handler + jobThread = HandlerRouter.registJobThread(jobKey, new GlueJobHandler(requestModel.getJobGroup(), requestModel.getJobName())); + } } } // sometime, cmap.get can not return given value, i do not know why - jobThread = HandlerRouter.loadJobThread(jobKey); + if (jobThread == null) { + jobThread = HandlerRouter.loadJobThread(jobKey); + } // push data to queue jobThread.pushTriggerQueue(requestModel); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/JobThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/JobThread.java index 3a9dcee5..4c8e6de5 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/JobThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/JobThread.java @@ -4,7 +4,6 @@ import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.IJobHandler.JobHandleStatus; import com.xxl.job.core.log.XxlJobFileAppender; import com.xxl.job.core.router.model.RequestModel; -import com.xxl.job.core.util.XxlJobNetCommUtil; import org.eclipse.jetty.util.ConcurrentHashSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,7 +87,7 @@ public class JobThread extends Thread{ e.printStackTrace(new PrintWriter(out)); _msg = out.toString(); } - logger.info("----------- xxl-job job handle end -----------
: ExecutorParams:{}, Status:{}, Msg:{}", + logger.info("----------- xxl-job job handle end -----------
Look : ExecutorParams:{}, Status:{}, Msg:{}", new Object[]{handlerParams, _status, _msg}); // callback handler info @@ -100,7 +99,7 @@ public class JobThread extends Thread{ } else { // is killed triggerDate.setStatus(JobHandleStatus.FAIL.name()); - triggerDate.setMsg(stopReason + "人工手动终止[业务运行中,被强制终止]"); + triggerDate.setMsg(stopReason + " [业务运行中,被强制终止]"); TriggerCallbackThread.pushCallBack(triggerDate); } } @@ -114,12 +113,9 @@ public class JobThread extends Thread{ RequestModel triggerDate = triggerQueue.poll(); if (triggerDate!=null) { // is killed - RequestModel callback = new RequestModel(); - callback.setLogAddress(XxlJobNetCommUtil.addressToUrl(triggerDate.getLogAddress())); - callback.setLogId(triggerDate.getLogId()); - callback.setStatus(JobHandleStatus.FAIL.name()); - callback.setMsg(stopReason + "[任务尚未执行,在调度队列中被终止]"); - TriggerCallbackThread.pushCallBack(callback); + triggerDate.setStatus(JobHandleStatus.FAIL.name()); + triggerDate.setMsg(stopReason + " [任务尚未执行,在调度队列中被终止]"); + TriggerCallbackThread.pushCallBack(triggerDate); } } diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java index fd0352f5..ade01068 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java @@ -39,6 +39,7 @@ public class TriggerCallbackThread { } public static void pushCallBack(RequestModel callback){ callBackQueue.add(callback); + logger.debug(">>>>>>>>>>> xxl-job, push callback request, logId:{}", callback.getLogId()); } }