From 8a8d7a5caf0a65a384b296aaeda2d12d039d731d Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Mon, 18 Jul 2016 23:24:51 +0800 Subject: [PATCH] coding snapshot --- README.md | 14 +- db/tables_xxl_job.sql | 14 +- .../admin/controller/JobInfoController.java | 6 +- .../admin/controller/JobLogController.java | 7 + .../job/admin/core/constant/Constants.java | 6 +- .../com/xxl/job/admin/dao/IXxlJobInfoDao.java | 8 +- .../job/admin/dao/impl/XxlJobInfoDaoImpl.java | 16 +- .../xxl/job/admin/service/IXxlJobService.java | 4 +- .../admin/service/impl/XxlJobServiceImpl.java | 22 +- .../src/main/resources/log4j.properties | 2 +- .../mybatis-mapper/XxlJobInfoMapper.xml | 26 ++- .../mybatis-mapper/XxlJobLogGlueMapper.xml | 8 +- .../mybatis-mapper/XxlJobLogMapper.xml | 14 +- .../template/jobinfo/jobinfo.index.ftl | 96 +++++---- .../WEB-INF/template/joblog/joblog.index.ftl | 13 +- .../main/webapp/static/js/jobinfo.index.1.js | 201 ++++++++---------- .../main/webapp/static/js/joblog.index.1.js | 32 +++ .../src/main/resources/log4j.xml | 4 +- .../mybatis-mapper/XxlJobInfoMapper.xml | 2 +- 19 files changed, 269 insertions(+), 226 deletions(-) diff --git a/README.md b/README.md index 18df94d2..20a058b8 100644 --- a/README.md +++ b/README.md @@ -251,11 +251,21 @@ XXL-JOB会为每次调度请求生成一个单独的日志文件,通过重写L - 2、执行器异步回调执行日志; - 3、【重要】在 “调度中心” 支持HA的基础上,扩展执行器的Failover支持,支持配置多执行期地址; +#### 4.6 版本 V1.4.0 新特性 +- 1、任务依赖: 通过事件触发方式实现, 任务执行成功并回调SUCCESS时, 会主动触发一次依赖任务的调度; +- 2、调度中心任务属性调整: jobName改为系统生成, 新增任务时不需要指定; +- 3、问题修复: + - 1.1、执行器jetty关闭优化,解决一处可能导致jetty无法关闭的问题; + - 1.2、执行器任务终止时,执行队列回调优化,解决一处导致任务无法回调的问题; + - 1.3、调度中心中列表分页参数优化,解决一处因服务器限制post长度而引起的问题; + - 1.4、执行器Jobhandler注解优化,解决一处因事务代理导致的容器无法加载JobHandler的问题; + - 1.5、远程调度优化,禁用retry策略,解决一处可能导致重复调用的问题; + + #### 规划中 -- 1、任务终止时,任务队列中调度回调通过被终止的接口; - 2、任务执行规则自定义:假如前一个任务正在执行,后续调度执行规则支持自定义; 串行(默认,当前逻辑):后续调度入调度队列; 并行:后续调度并行执行; Pass:后续调度被Pass; - 3、兼容oracle; -- 4、任务依赖; + diff --git a/db/tables_xxl_job.sql b/db/tables_xxl_job.sql index 7766ddd1..c632ed28 100644 --- a/db/tables_xxl_job.sql +++ b/db/tables_xxl_job.sql @@ -143,7 +143,9 @@ CREATE TABLE XXL_JOB_QRTZ_LOCKS PRIMARY KEY (SCHED_NAME,LOCK_NAME) ); -CREATE TABLE `xxl_job_qrtz_trigger_info` ( + + +CREATE TABLE XXL_JOB_QRTZ_TRIGGER_INFO ( `id` int(11) NOT NULL AUTO_INCREMENT, `job_group` varchar(255) NOT NULL COMMENT '任务组', `job_name` varchar(255) NOT NULL COMMENT '任务名', @@ -162,9 +164,9 @@ CREATE TABLE `xxl_job_qrtz_trigger_info` ( `glue_source` text COMMENT 'GLUE源代码', `glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE备注', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `xxl_job_qrtz_trigger_log` ( +CREATE TABLE XXL_JOB_QRTZ_TRIGGER_LOG ( `id` int(11) NOT NULL AUTO_INCREMENT, `job_group` varchar(255) NOT NULL COMMENT '任务组', `job_name` varchar(255) NOT NULL COMMENT '任务名', @@ -181,9 +183,9 @@ CREATE TABLE `xxl_job_qrtz_trigger_log` ( `handle_status` varchar(255) DEFAULT NULL COMMENT '执行-状态', `handle_msg` varchar(2048) DEFAULT NULL COMMENT '执行-日志', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `xxl_job_qrtz_trigger_logglue` ( +CREATE TABLE XXL_JOB_QRTZ_TRIGGER_LOGGLUE ( `id` int(11) NOT NULL AUTO_INCREMENT, `job_group` varchar(255) NOT NULL, `job_name` varchar(255) NOT NULL, @@ -192,7 +194,7 @@ CREATE TABLE `xxl_job_qrtz_trigger_logglue` ( `add_time` timestamp NULL DEFAULT NULL, `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java index 82e46ef3..d644df59 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java @@ -35,9 +35,9 @@ public class JobInfoController { @ResponseBody public Map pageList(@RequestParam(required = false, defaultValue = "0") int start, @RequestParam(required = false, defaultValue = "10") int length, - String jobGroup, String jobName, String filterTime) { + String jobGroup, String jobDesc, String filterTime) { - return xxlJobService.pageList(start, length, jobGroup, jobName, filterTime); + return xxlJobService.pageList(start, length, jobGroup, jobDesc, filterTime); } @RequestMapping("/add") @@ -47,7 +47,7 @@ public class JobInfoController { String author, String alarmEmail, int alarmThreshold, int glueSwitch, String glueSource, String glueRemark) { - return xxlJobService.add(jobGroup, jobName, jobCron, jobDesc, executorAddress, executorHandler, executorParam, + return xxlJobService.add(jobGroup, jobCron, jobDesc, executorAddress, executorHandler, executorParam, author, alarmEmail, alarmThreshold, glueSwitch, glueSource, glueRemark); } 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 073af8c7..f9c71fd0 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 @@ -47,6 +47,13 @@ public class JobLogController { model.addAttribute("JobGroupList", JobGroupEnum.values()); return "joblog/joblog.index"; } + + @RequestMapping("/getJobsByGroup") + @ResponseBody + public ReturnT> listJobByGroup(String jobGroup){ + List list = xxlJobInfoDao.getJobsByGroup(jobGroup); + return new ReturnT>(list); + } @RequestMapping("/pageList") @ResponseBody diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/constant/Constants.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/constant/Constants.java index ae2625b7..210a518c 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/constant/Constants.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/constant/Constants.java @@ -7,9 +7,9 @@ package com.xxl.job.admin.core.constant; public class Constants { public enum JobGroupEnum{ - DEFAULT("默认"), - WAIMAI("外卖"), - MOVIE("电影"); + defaults("默认"), + waimai("外卖"), + movie("电影"); private String desc; private JobGroupEnum(String desc){ this.desc = desc; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/IXxlJobInfoDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/IXxlJobInfoDao.java index 972d1a65..d78c87f6 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/IXxlJobInfoDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/IXxlJobInfoDao.java @@ -3,6 +3,7 @@ package com.xxl.job.admin.dao; import java.util.List; import com.xxl.job.admin.core.model.XxlJobInfo; +import com.xxl.job.admin.core.model.XxlJobLog; /** @@ -11,8 +12,8 @@ import com.xxl.job.admin.core.model.XxlJobInfo; */ public interface IXxlJobInfoDao { - public List pageList(int offset, int pagesize, String jobGroup, String jobName); - public int pageListCount(int offset, int pagesize, String jobGroup, String jobName); + public List pageList(int offset, int pagesize, String jobGroup, String jobDesc); + public int pageListCount(int offset, int pagesize, String jobGroup, String jobDesc); public int save(XxlJobInfo info); @@ -21,5 +22,6 @@ public interface IXxlJobInfoDao { public int update(XxlJobInfo item); public int delete(String jobGroup, String jobName); - + + public List getJobsByGroup(String jobGroup); } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/impl/XxlJobInfoDaoImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/impl/XxlJobInfoDaoImpl.java index c31f47de..bfb9a397 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/impl/XxlJobInfoDaoImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/impl/XxlJobInfoDaoImpl.java @@ -5,6 +5,7 @@ import java.util.List; import javax.annotation.Resource; +import com.xxl.job.admin.core.model.XxlJobLog; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.stereotype.Repository; @@ -22,23 +23,23 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao { public SqlSessionTemplate sqlSessionTemplate; @Override - public List pageList(int offset, int pagesize, String jobGroup, String jobName) { + public List pageList(int offset, int pagesize, String jobGroup, String jobDesc) { HashMap params = new HashMap(); params.put("offset", offset); params.put("pagesize", pagesize); params.put("jobGroup", jobGroup); - params.put("jobName", jobName); + params.put("jobDesc", jobDesc); return sqlSessionTemplate.selectList("XxlJobInfoMapper.pageList", params); } @Override - public int pageListCount(int offset, int pagesize, String jobGroup, String jobName) { + public int pageListCount(int offset, int pagesize, String jobGroup, String jobDesc) { HashMap params = new HashMap(); params.put("offset", offset); params.put("pagesize", pagesize); params.put("jobGroup", jobGroup); - params.put("jobName", jobName); + params.put("jobDesc", jobDesc); return sqlSessionTemplate.selectOne("XxlJobInfoMapper.pageListCount", params); } @@ -70,5 +71,10 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao { return sqlSessionTemplate.update("XxlJobInfoMapper.delete", params); } - + + @Override + public List getJobsByGroup(String jobGroup) { + return sqlSessionTemplate.selectList("XxlJobInfoMapper.getJobsByGroup", jobGroup); + } + } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java index 444a1b7a..51003f10 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java @@ -11,9 +11,9 @@ import com.xxl.job.admin.core.model.ReturnT; */ public interface IXxlJobService { - public Map pageList(int start, int length, String jobGroup, String jobName, String filterTime); + public Map pageList(int start, int length, String jobGroup, String jobDesc, String filterTime); - public ReturnT add(String jobGroup, String jobName, String jobCron, String jobDesc, + public ReturnT add(String jobGroup, String jobCron, String jobDesc, String executorAddress, String executorHandler, String executorParam, String author, String alarmEmail, int alarmThreshold, int glueSwitch, String glueSource, String glueRemark); 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 7ea392fc..89daa08a 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 @@ -3,6 +3,7 @@ package com.xxl.job.admin.service.impl; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import javax.annotation.Resource; @@ -36,11 +37,11 @@ public class XxlJobServiceImpl implements IXxlJobService { private IXxlJobLogGlueDao xxlJobLogGlueDao; @Override - public Map pageList(int start, int length, String jobGroup, String jobName, String filterTime) { + public Map pageList(int start, int length, String jobGroup, String jobDesc, String filterTime) { // page list - List list = xxlJobInfoDao.pageList(start, length, jobGroup, jobName); - int list_count = xxlJobInfoDao.pageListCount(start, length, jobGroup, jobName); + List list = xxlJobInfoDao.pageList(start, length, jobGroup, jobDesc); + int list_count = xxlJobInfoDao.pageListCount(start, length, jobGroup, jobDesc); // fill job info if (list!=null && list.size()>0) { @@ -58,7 +59,7 @@ public class XxlJobServiceImpl implements IXxlJobService { } @Override - public ReturnT add(String jobGroup, String jobName, String jobCron, String jobDesc, + public ReturnT add(String jobGroup, String jobCron, String jobDesc, String executorAddress, String executorHandler, String executorParam, String author, String alarmEmail, int alarmThreshold, int glueSwitch, String glueSource, String glueRemark) { @@ -66,9 +67,6 @@ public class XxlJobServiceImpl implements IXxlJobService { if (JobGroupEnum.match(jobGroup) == null) { return new ReturnT(500, "请选择“任务组”"); } - if (StringUtils.isBlank(jobName)) { - return new ReturnT(500, "请输入“任务名”"); - } if (!CronExpression.isValidExpression(jobCron)) { return new ReturnT(500, "请输入格式正确的“Cron”"); } @@ -90,7 +88,9 @@ public class XxlJobServiceImpl implements IXxlJobService { if (alarmThreshold < 0) { alarmThreshold = 0; } - + + // generate jobName + String jobName = UUID.randomUUID().toString(); try { if (DynamicSchedulerUtil.checkExists(jobName, jobGroup)) { return new ReturnT(500, "此任务已存在,请更换任务组或任务名"); @@ -99,7 +99,7 @@ public class XxlJobServiceImpl implements IXxlJobService { e1.printStackTrace(); return new ReturnT(500, "此任务已存在,请更换任务组或任务名"); } - + // Backup to the database XxlJobInfo jobInfo = new XxlJobInfo(); jobInfo.setJobGroup(jobGroup); @@ -117,7 +117,7 @@ public class XxlJobServiceImpl implements IXxlJobService { jobInfo.setExecutorHandler(executorHandler); jobInfo.setExecutorParam(executorParam); xxlJobInfoDao.save(jobInfo); - + try { // add job 2 quartz boolean result = DynamicSchedulerUtil.addJob(jobInfo); @@ -168,8 +168,8 @@ public class XxlJobServiceImpl implements IXxlJobService { } XxlJobInfo jobInfo = xxlJobInfoDao.load(jobGroup, jobName); - jobInfo.setJobCron(jobCron); jobInfo.setJobDesc(jobDesc); + jobInfo.setJobCron(jobCron); jobInfo.setAuthor(author); jobInfo.setAlarmEmail(alarmEmail); jobInfo.setAlarmThreshold(alarmThreshold); diff --git a/xxl-job-admin/src/main/resources/log4j.properties b/xxl-job-admin/src/main/resources/log4j.properties index f31fe38f..c9455ab0 100644 --- a/xxl-job-admin/src/main/resources/log4j.properties +++ b/xxl-job-admin/src/main/resources/log4j.properties @@ -5,6 +5,6 @@ log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d - xxl-job-admin - %p [%c] - <%m>%n log4j.appender.logFile=org.apache.log4j.DailyRollingFileAppender -log4j.appender.logFile.File=${catalina.base}/logs/xxl-job-admin.log +log4j.appender.logFile.File=/data/applogs/xxl-job/xxl-job-admin.log log4j.appender.logFile.layout=org.apache.log4j.PatternLayout log4j.appender.logFile.layout.ConversionPattern=%d - xxl-job-admin - %p [%c] - <%m>%n 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 8a02eea4..10b9d005 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml @@ -50,13 +50,13 @@ SELECT count(1) - FROM xxl_job_qrtz_trigger_info AS t + FROM XXL_JOB_QRTZ_TRIGGER_INFO AS t AND t.job_group = #{jobGroup} - - AND t.job_name like CONCAT(CONCAT('%', #{jobName}), '%') + + AND t.job_desc like CONCAT(CONCAT('%', #{jobDesc}), '%') - INSERT INTO `xxl_job_qrtz_trigger_info` ( + INSERT INTO XXL_JOB_QRTZ_TRIGGER_INFO ( job_group, job_name, job_cron, @@ -119,13 +119,13 @@ - UPDATE `xxl_job_qrtz_trigger_info` + UPDATE XXL_JOB_QRTZ_TRIGGER_INFO SET job_cron = #{jobCron}, job_desc = #{jobDesc}, @@ -146,10 +146,16 @@ DELETE FROM - xxl_job_qrtz_trigger_info + XXL_JOB_QRTZ_TRIGGER_INFO WHERE job_group = #{jobGroup} AND job_name = #{jobName} + + \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml index 5bc7a9f1..225ffdf8 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml @@ -46,7 +46,7 @@ - DELETE FROM xxl_job_qrtz_trigger_logglue + DELETE FROM XXL_JOB_QRTZ_TRIGGER_LOGGLUE WHERE id NOT in( SELECT id FROM( - SELECT id FROM xxl_job_qrtz_trigger_logglue + SELECT id FROM XXL_JOB_QRTZ_TRIGGER_LOGGLUE WHERE `job_group` = #{jobGroup} and `job_name` = #{jobName} ORDER BY update_time desc LIMIT 0, #{limit} @@ -71,7 +71,7 @@ - DELETE FROM xxl_job_qrtz_trigger_logglue + DELETE FROM XXL_JOB_QRTZ_TRIGGER_LOGGLUE WHERE job_group = #{jobGroup} and job_name = #{jobName} 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 198b26d2..9260e047 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml @@ -67,7 +67,7 @@ SELECT - FROM xxl_job_qrtz_trigger_log AS t + FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t WHERE t.id = #{id} - INSERT INTO `xxl_job_qrtz_trigger_log` ( + INSERT INTO XXL_JOB_QRTZ_TRIGGER_LOG ( `job_group`, `job_name`, `job_cron`, @@ -123,7 +123,7 @@ - UPDATE `xxl_job_qrtz_trigger_log` + UPDATE XXL_JOB_QRTZ_TRIGGER_LOG SET `trigger_time`= #{triggerTime}, `trigger_status`= #{triggerStatus}, @@ -135,7 +135,7 @@ - UPDATE `xxl_job_qrtz_trigger_log` + UPDATE XXL_JOB_QRTZ_TRIGGER_LOG SET `handle_time`= #{handleTime}, `handle_status`= #{handleStatus}, @@ -144,7 +144,7 @@ - delete from `xxl_job_qrtz_trigger_log` + delete from XXL_JOB_QRTZ_TRIGGER_LOG WHERE job_group = #{jobGroup} AND job_name = #{jobName} diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl index 5c6a6c11..a0b264b5 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl @@ -34,7 +34,7 @@
- 任务组 + 分组 + 名称 +
@@ -67,9 +67,9 @@ id - 任务组 - 任务名 - 描述 + jobGroup + jobName + 名称 Cron JobBean 执行器地址 @@ -104,12 +104,12 @@