From aef9ef6c66062497a4a8e8fb975f2345e15f3738 Mon Sep 17 00:00:00 2001
From: xuxueli <931591021@qq.com>
Date: Wed, 30 Aug 2017 23:19:41 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E8=B0=83=E5=BA=A6=EF=BC=9A?=
=?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=94=AF=E6=8C=81Cron=E3=80=81=E5=AD=90?=
=?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=A7=A6=E5=8F=91=E3=80=81=E4=BA=8B=E4=BB=B6?=
=?UTF-8?q?=E8=A7=A6=E5=8F=91=EF=BC=88API=EF=BC=89=E4=B8=89=E7=A7=8D?=
=?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=A7=A6=E5=8F=91=E4=BB=BB=E5=8A=A1=E8=B0=83?=
=?UTF-8?q?=E5=BA=A6=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
doc/XXL-JOB官方文档.md | 1 +
.../job/admin/core/trigger/XxlJobTrigger.java | 4 ++++
.../job/admin/service/impl/AdminBizImpl.java | 19 ++++---------------
.../admin/service/impl/XxlJobServiceImpl.java | 6 +++++-
.../WEB-INF/template/common/common.macro.ftl | 4 ++--
5 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md
index 8799390a..143b1305 100644
--- a/doc/XXL-JOB官方文档.md
+++ b/doc/XXL-JOB官方文档.md
@@ -992,6 +992,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 7、执行器注册线程销毁时, 主动摘除注册机器信息,提高执行器注册的实时性;
- 8、调度中心任务监控线程销毁时,批量对失败任务告警,防止告警信息丢失;
- 9、调度中心API服务:支持API方式触发任务执行;
+- 10、事件调度:系统支持Cron、子任务触发、事件触发(API)三种方式触发任务调度;
### TODO LIST
- 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java
index 7c916b9b..48fc850a 100644
--- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java
+++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java
@@ -34,6 +34,10 @@ public class XxlJobTrigger {
// load data
XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId); // job info
+ if (jobInfo == null) {
+ logger.warn(">>>>>>>>>>>> xxl-job trigger fail, jobId invalid,jobId={}", jobId);
+ return;
+ }
XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup()); // group info
ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION); // block strategy
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java
index 158ac37a..a2f05cae 100644
--- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java
+++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java
@@ -69,21 +69,10 @@ public class AdminBizImpl implements AdminBiz {
for (int i = 0; i < childJobKeys.length; i++) {
String[] jobKeyArr = childJobKeys[i].split("_");
if (jobKeyArr!=null && jobKeyArr.length==2) {
- XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(jobKeyArr[1]));
- if (childJobInfo!=null) {
- try {
- boolean ret = XxlJobDynamicScheduler.triggerJob(String.valueOf(childJobInfo.getId()), String.valueOf(childJobInfo.getJobGroup()));
-
- // add msg
- childTriggerMsg += MessageFormat.format("
{0}/{1} 触发子任务成功, 子任务Key: {2}, status: {3}, 子任务描述: {4}",
- (i+1), childJobKeys.length, childJobKeys[i], ret, childJobInfo.getJobDesc());
- } catch (SchedulerException e) {
- logger.error(e.getMessage(), e);
- }
- } else {
- childTriggerMsg += MessageFormat.format("
{0}/{1} 触发子任务失败, 子任务xxlJobInfo不存在, 子任务Key: {2}",
- (i+1), childJobKeys.length, childJobKeys[i]);
- }
+ ReturnT triggerChildResult = xxlJobService.triggerJob(Integer.valueOf(jobKeyArr[1]));
+ // add msg
+ childTriggerMsg += MessageFormat.format("
{0}/{1} 触发子任务{2}, 子任务Key: {3}, 子任务触发备注: {4}",
+ (i+1), childJobKeys.length, (triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?"成功":"失败"), childJobKeys[i], triggerChildResult.getMsg());
} else {
childTriggerMsg += MessageFormat.format("
{0}/{1} 触发子任务失败, 子任务Key格式错误, 子任务Key: {2}",
(i+1), childJobKeys.length, childJobKeys[i]);
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
index d144eff2..65d53971 100644
--- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
+++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
@@ -264,6 +264,10 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
public ReturnT triggerJob(int id) {
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
+ if (xxlJobInfo == null) {
+ return new ReturnT(ReturnT.FAIL_CODE, "任务ID非法");
+ }
+
String group = String.valueOf(xxlJobInfo.getJobGroup());
String name = String.valueOf(xxlJobInfo.getId());
@@ -272,7 +276,7 @@ public class XxlJobServiceImpl implements XxlJobService {
return ReturnT.SUCCESS;
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
- return ReturnT.FAIL;
+ return new ReturnT(ReturnT.FAIL_CODE, e.getMessage());
}
}
diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl
index e7db9c38..fa84ceaf 100644
--- a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl
+++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl
@@ -60,8 +60,8 @@
<#macro commonHeader>