正在显示
4 个修改的文件
包含
18 行增加
和
6 行删除
| @@ -167,8 +167,8 @@ public class SysJobController extends BaseController | @@ -167,8 +167,8 @@ public class SysJobController extends BaseController | ||
| 167 | @PutMapping("/run") | 167 | @PutMapping("/run") |
| 168 | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException | 168 | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException |
| 169 | { | 169 | { |
| 170 | - jobService.run(job); | ||
| 171 | - return AjaxResult.success(); | 170 | + boolean result = jobService.run(job); |
| 171 | + return result ? success() : error("任务不存在或已过期!"); | ||
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | /** | 174 | /** |
| @@ -180,6 +180,6 @@ public class SysJobController extends BaseController | @@ -180,6 +180,6 @@ public class SysJobController extends BaseController | ||
| 180 | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException | 180 | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException |
| 181 | { | 181 | { |
| 182 | jobService.deleteJobByIds(jobIds); | 182 | jobService.deleteJobByIds(jobIds); |
| 183 | - return AjaxResult.success(); | 183 | + return success(); |
| 184 | } | 184 | } |
| 185 | } | 185 | } |
| @@ -74,7 +74,7 @@ public interface ISysJobService | @@ -74,7 +74,7 @@ public interface ISysJobService | ||
| 74 | * @param job 调度信息 | 74 | * @param job 调度信息 |
| 75 | * @return 结果 | 75 | * @return 结果 |
| 76 | */ | 76 | */ |
| 77 | - public void run(SysJob job) throws SchedulerException; | 77 | + public boolean run(SysJob job) throws SchedulerException; |
| 78 | 78 | ||
| 79 | /** | 79 | /** |
| 80 | * 新增任务 | 80 | * 新增任务 |
| @@ -174,15 +174,22 @@ public class SysJobServiceImpl implements ISysJobService | @@ -174,15 +174,22 @@ public class SysJobServiceImpl implements ISysJobService | ||
| 174 | */ | 174 | */ |
| 175 | @Override | 175 | @Override |
| 176 | @Transactional(rollbackFor = Exception.class) | 176 | @Transactional(rollbackFor = Exception.class) |
| 177 | - public void run(SysJob job) throws SchedulerException | 177 | + public boolean run(SysJob job) throws SchedulerException |
| 178 | { | 178 | { |
| 179 | + boolean result = false; | ||
| 179 | Long jobId = job.getJobId(); | 180 | Long jobId = job.getJobId(); |
| 180 | String jobGroup = job.getJobGroup(); | 181 | String jobGroup = job.getJobGroup(); |
| 181 | SysJob properties = selectJobById(job.getJobId()); | 182 | SysJob properties = selectJobById(job.getJobId()); |
| 182 | // 参数 | 183 | // 参数 |
| 183 | JobDataMap dataMap = new JobDataMap(); | 184 | JobDataMap dataMap = new JobDataMap(); |
| 184 | dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); | 185 | dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); |
| 185 | - scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap); | 186 | + JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); |
| 187 | + if (scheduler.checkExists(jobKey)) | ||
| 188 | + { | ||
| 189 | + result = true; | ||
| 190 | + scheduler.triggerJob(jobKey, dataMap); | ||
| 191 | + } | ||
| 192 | + return result; | ||
| 186 | } | 193 | } |
| 187 | 194 | ||
| 188 | /** | 195 | /** |
| @@ -83,7 +83,12 @@ public class ScheduleUtils | @@ -83,7 +83,12 @@ public class ScheduleUtils | ||
| 83 | scheduler.deleteJob(getJobKey(jobId, jobGroup)); | 83 | scheduler.deleteJob(getJobKey(jobId, jobGroup)); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | + // 判断任务是否过期 | ||
| 87 | + if (StringUtils.isNotNull(CronUtils.getNextExecution(job.getCronExpression()))) | ||
| 88 | + { | ||
| 89 | + // 执行调度任务 | ||
| 86 | scheduler.scheduleJob(jobDetail, trigger); | 90 | scheduler.scheduleJob(jobDetail, trigger); |
| 91 | + } | ||
| 87 | 92 | ||
| 88 | // 暂停任务 | 93 | // 暂停任务 |
| 89 | if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) | 94 | if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) |
-
请 注册 或 登录 后发表评论