From 32a843534cf215990f7abe4974fd81f688e02d1d Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Thu, 21 Feb 2019 19:08:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=94=AF=E6=8C=81=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E7=BB=91=E5=AE=9A=E6=89=A7=E8=A1=8C=E5=99=A8=EF=BC=8C?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E4=BB=BB=E5=8A=A1=E5=88=86=E7=BB=84=E8=BD=AC?= =?UTF-8?q?=E7=A7=BB=E5=92=8C=E7=AE=A1=E7=90=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 2 +- .../core/schedule/XxlJobDynamicScheduler.java | 43 ++++++++----------- .../com/xxl/job/admin/dao/XxlJobLogDao.java | 3 +- .../admin/service/impl/XxlJobServiceImpl.java | 27 +++++++----- .../mybatis-mapper/XxlJobInfoMapper.xml | 1 + .../mybatis-mapper/XxlJobLogMapper.xml | 4 +- .../templates/jobinfo/jobinfo.index.ftl | 2 +- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 6ebad61a..818983fb 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1423,7 +1423,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 9、任务暂停、删除优化,避免quartz delete不完整导致任务脏数据; - 10、任务回调、心跳注册成功日志优化,非核心常规日志调整为debug级别,降低冗余日志输出; - 11、执行器回调日志落盘方案复用RPC序列化方案,并移除Jackson依赖; -- [迭代中]任务支持更换绑定执行器; +- 12、任务支持更换绑定执行器,方便任务分组转移和管理; - [迭代中]注册中心优化,实时性注册发现:心跳注册间隔10s,refresh失败则首次注册并立即更新注册信息,心跳类似;30s过期销毁; - [迭代中]脚本任务,支持数据参数,新版本仅支持单参数不支持需要兼容; - [迭代中]提供执行器Docker镜像; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java index 6056a36e..2ee99b2c 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java @@ -164,11 +164,10 @@ public final class XxlJobDynamicScheduler { */ public static void fillJobInfo(XxlJobInfo jobInfo) { - String group = String.valueOf(jobInfo.getJobGroup()); String name = String.valueOf(jobInfo.getId()); // trigger key - TriggerKey triggerKey = TriggerKey.triggerKey(name, group); + TriggerKey triggerKey = TriggerKey.triggerKey(name); try { // trigger cron @@ -198,15 +197,14 @@ public final class XxlJobDynamicScheduler { * add trigger + job * * @param jobName - * @param jobGroup * @param cronExpression * @return * @throws SchedulerException */ - public static boolean addJob(String jobName, String jobGroup, String cronExpression) throws SchedulerException { + public static boolean addJob(String jobName, String cronExpression) throws SchedulerException { // 1、job key - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup); - JobKey jobKey = new JobKey(jobName, jobGroup); + TriggerKey triggerKey = TriggerKey.triggerKey(jobName); + JobKey jobKey = new JobKey(jobName); // 2、valid if (scheduler.checkExists(triggerKey)) { @@ -239,16 +237,15 @@ public final class XxlJobDynamicScheduler { * remove trigger + job * * @param jobName - * @param jobGroup * @return * @throws SchedulerException */ - public static boolean removeJob(String jobName, String jobGroup) throws SchedulerException { + public static boolean removeJob(String jobName) throws SchedulerException { - JobKey jobKey = new JobKey(jobName, jobGroup); + JobKey jobKey = new JobKey(jobName); scheduler.deleteJob(jobKey); - /*TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup); + /*TriggerKey triggerKey = TriggerKey.triggerKey(jobName); if (scheduler.checkExists(triggerKey)) { scheduler.unscheduleJob(triggerKey); // trigger + job }*/ @@ -261,16 +258,15 @@ public final class XxlJobDynamicScheduler { /** * updateJobCron * - * @param jobGroup * @param jobName * @param cronExpression * @return * @throws SchedulerException */ - public static boolean updateJobCron(String jobGroup, String jobName, String cronExpression) throws SchedulerException { + public static boolean updateJobCron(String jobName, String cronExpression) throws SchedulerException { // 1、job key - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup); + TriggerKey triggerKey = TriggerKey.triggerKey(jobName); // 2、valid if (!scheduler.checkExists(triggerKey)) { @@ -293,7 +289,7 @@ public final class XxlJobDynamicScheduler { scheduler.rescheduleJob(triggerKey, oldTrigger); /* - JobKey jobKey = new JobKey(jobName, jobGroup); + JobKey jobKey = new JobKey(jobName); // old job detail JobDetail jobDetail = scheduler.getJobDetail(jobKey); @@ -304,7 +300,7 @@ public final class XxlJobDynamicScheduler { // cover trigger of job detail scheduler.scheduleJob(jobDetail, triggerSet, true);*/ - logger.info(">>>>>>>>>>> resumeJob success, JobGroup:{}, JobName:{}", jobGroup, jobName); + logger.info(">>>>>>>>>>> resumeJob success, JobName:{}", jobName); return true; } @@ -313,13 +309,12 @@ public final class XxlJobDynamicScheduler { * pause * * @param jobName - * @param jobGroup * @return * @throws SchedulerException */ - /*public static boolean pauseJob(String jobName, String jobGroup) throws SchedulerException { + /*public static boolean pauseJob(String jobName) throws SchedulerException { - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup); + TriggerKey triggerKey = TriggerKey.triggerKey(jobName); boolean result = false; if (scheduler.checkExists(triggerKey)) { @@ -336,13 +331,12 @@ public final class XxlJobDynamicScheduler { * resume * * @param jobName - * @param jobGroup * @return * @throws SchedulerException */ - /*public static boolean resumeJob(String jobName, String jobGroup) throws SchedulerException { + /*public static boolean resumeJob(String jobName) throws SchedulerException { - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup); + TriggerKey triggerKey = TriggerKey.triggerKey(jobName); boolean result = false; if (scheduler.checkExists(triggerKey)) { @@ -359,14 +353,13 @@ public final class XxlJobDynamicScheduler { * run * * @param jobName - * @param jobGroup * @return * @throws SchedulerException */ - /*public static boolean triggerJob(String jobName, String jobGroup) throws SchedulerException { + /*public static boolean triggerJob(String jobName) throws SchedulerException { // TriggerKey : name + group - JobKey jobKey = new JobKey(jobName, jobGroup); - TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup); + JobKey jobKey = new JobKey(jobName); + TriggerKey triggerKey = TriggerKey.triggerKey(jobName); boolean result = false; if (scheduler.checkExists(triggerKey)) { diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java index cb5848e3..9b632ec6 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java @@ -14,7 +14,8 @@ import java.util.Map; */ @Mapper public interface XxlJobLogDao { - + + // exist jobId not use jobGroup, not exist use jobGroup public List pageList(@Param("offset") int offset, @Param("pagesize") int pagesize, @Param("jobGroup") int jobGroup, 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 6b6ee268..a037a023 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 @@ -164,13 +164,19 @@ public class XxlJobServiceImpl implements XxlJobService { jobInfo.setChildJobId(StringUtils.join(childJobIds, ",")); } + // group valid + XxlJobGroup jobGroup = xxlJobGroupDao.load(jobInfo.getJobGroup()); + if (jobGroup == null) { + return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) ); + } + // stage job info XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId()); if (exists_jobInfo == null) { return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) ); } - //String old_cron = exists_jobInfo.getJobCron(); + exists_jobInfo.setJobGroup(jobInfo.getJobGroup()); exists_jobInfo.setJobCron(jobInfo.getJobCron()); exists_jobInfo.setJobDesc(jobInfo.getJobDesc()); exists_jobInfo.setAuthor(jobInfo.getAuthor()); @@ -186,10 +192,9 @@ public class XxlJobServiceImpl implements XxlJobService { // update quartz-cron if started - String qz_group = String.valueOf(exists_jobInfo.getJobGroup()); - String qz_name = String.valueOf(exists_jobInfo.getId()); try { - XxlJobDynamicScheduler.updateJobCron(qz_group, qz_name, exists_jobInfo.getJobCron()); + String qz_name = String.valueOf(exists_jobInfo.getId()); + XxlJobDynamicScheduler.updateJobCron(qz_name, exists_jobInfo.getJobCron()); } catch (SchedulerException e) { logger.error(e.getMessage(), e); return ReturnT.FAIL; @@ -201,12 +206,14 @@ public class XxlJobServiceImpl implements XxlJobService { @Override public ReturnT remove(int id) { XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); - String group = String.valueOf(xxlJobInfo.getJobGroup()); - String name = String.valueOf(xxlJobInfo.getId()); + if (xxlJobInfo == null) { + return ReturnT.SUCCESS; + } + String name = String.valueOf(xxlJobInfo.getId()); try { // unbind quartz - XxlJobDynamicScheduler.removeJob(name, group); + XxlJobDynamicScheduler.removeJob(name); xxlJobInfoDao.delete(id); xxlJobLogDao.delete(id); @@ -222,12 +229,11 @@ public class XxlJobServiceImpl implements XxlJobService { @Override public ReturnT start(int id) { XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); - String group = String.valueOf(xxlJobInfo.getJobGroup()); String name = String.valueOf(xxlJobInfo.getId()); String cronExpression = xxlJobInfo.getJobCron(); try { - boolean ret = XxlJobDynamicScheduler.addJob(name, group, cronExpression); + boolean ret = XxlJobDynamicScheduler.addJob(name, cronExpression); return ret?ReturnT.SUCCESS:ReturnT.FAIL; } catch (SchedulerException e) { logger.error(e.getMessage(), e); @@ -238,12 +244,11 @@ public class XxlJobServiceImpl implements XxlJobService { @Override public ReturnT stop(int id) { XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); - String group = String.valueOf(xxlJobInfo.getJobGroup()); String name = String.valueOf(xxlJobInfo.getId()); try { // bind quartz - boolean ret = XxlJobDynamicScheduler.removeJob(name, group); + boolean ret = XxlJobDynamicScheduler.removeJob(name); return ret?ReturnT.SUCCESS:ReturnT.FAIL; } catch (SchedulerException e) { logger.error(e.getMessage(), e); diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml index 0aafba4d..3b3b9cec 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml @@ -142,6 +142,7 @@ UPDATE XXL_JOB_QRTZ_TRIGGER_INFO SET + job_group = #{jobGroup}, job_cron = #{jobCron}, job_desc = #{jobDesc}, update_time = NOW(), diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml index 9d69eb11..535e1aac 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml @@ -48,7 +48,7 @@ SELECT FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t - + AND t.job_group = #{jobGroup} @@ -82,7 +82,7 @@ SELECT count(1) FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t - + AND t.job_group = #{jobGroup} diff --git a/xxl-job-admin/src/main/resources/templates/jobinfo/jobinfo.index.ftl b/xxl-job-admin/src/main/resources/templates/jobinfo/jobinfo.index.ftl index b231200d..426b51f0 100644 --- a/xxl-job-admin/src/main/resources/templates/jobinfo/jobinfo.index.ftl +++ b/xxl-job-admin/src/main/resources/templates/jobinfo/jobinfo.index.ftl @@ -301,7 +301,7 @@ exit 0
- <#list JobGroupList as group>