From 8d99be356ad682454af4a3d4625412ec9951b558 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Sun, 12 Mar 2017 18:22:05 +0800 Subject: [PATCH] Coding --- .../admin/service/impl/XxlJobServiceImpl.java | 33 ++++++++++++------- .../main/webapp/static/js/jobinfo.index.1.js | 4 +-- 2 files changed, 24 insertions(+), 13 deletions(-) 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 2e53e375..b9a337be 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 @@ -105,11 +105,27 @@ public class XxlJobServiceImpl implements IXxlJobService { // add in db xxlJobInfoDao.save(jobInfo); - int jobId = jobInfo.getId(); - if (jobId < 1) { + if (jobInfo.getId() < 1) { return new ReturnT(500, "新增任务失败"); } - return ReturnT.SUCCESS; + + // add in quartz + String qz_group = String.valueOf(jobInfo.getJobGroup()); + String qz_name = String.valueOf(jobInfo.getId()); + try { + XxlJobDynamicScheduler.addJob(qz_name, qz_group, jobInfo.getJobCron()); + XxlJobDynamicScheduler.pauseJob(qz_name, qz_group); + return ReturnT.SUCCESS; + } catch (SchedulerException e) { + logger.error("", e); + try { + xxlJobInfoDao.delete(jobInfo.getId()); + XxlJobDynamicScheduler.removeJob(qz_name, qz_group); + } catch (SchedulerException e1) { + logger.error("", e1); + } + return new ReturnT(500, "新增任务失败:" + e.getMessage()); + } } @Override @@ -206,8 +222,8 @@ public class XxlJobServiceImpl implements IXxlJobService { String name = String.valueOf(xxlJobInfo.getId()); try { - XxlJobDynamicScheduler.pauseJob(name, group); // jobStatus do not store - return ReturnT.SUCCESS; + boolean ret = XxlJobDynamicScheduler.pauseJob(name, group); // jobStatus do not store + return ret?ReturnT.SUCCESS:ReturnT.FAIL; } catch (SchedulerException e) { e.printStackTrace(); return ReturnT.FAIL; @@ -221,12 +237,7 @@ public class XxlJobServiceImpl implements IXxlJobService { String name = String.valueOf(xxlJobInfo.getId()); try { - boolean ret = false; - if (XxlJobDynamicScheduler.checkExists(name, group)) { - ret = XxlJobDynamicScheduler.resumeJob(name, group); - } else { - ret = XxlJobDynamicScheduler.addJob(name, group, xxlJobInfo.getJobCron()); - } + boolean ret = XxlJobDynamicScheduler.resumeJob(name, group); return ret?ReturnT.SUCCESS:ReturnT.FAIL; } catch (SchedulerException e) { e.printStackTrace(); diff --git a/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js b/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js index a2062067..e284ea95 100644 --- a/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js +++ b/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js @@ -75,7 +75,7 @@ $(function() { "render": function ( data, type, row ) { if ('NORMAL' == data) { return ''+ data +''; - } else if ('PAUSED' == data || 'NONE' == data){ + } else if ('PAUSED' == data){ return ''+ data +''; } else if ('BLOCKED' == data){ return ''+ data +''; @@ -90,7 +90,7 @@ $(function() { var pause_resume = ""; if ('NORMAL' == row.jobStatus) { pause_resume = ' '; - } else if ('PAUSED' == row.jobStatus || 'NONE' == row.jobStatus){ + } else if ('PAUSED' == row.jobStatus){ pause_resume = ' '; } // log url