优化任务过期不执行调度

master
RuoYi 2022-07-29 20:07:29 +08:00
parent 2a0fcdea21
commit 08f775da4b
4 changed files with 18 additions and 6 deletions

View File

@ -111,8 +111,8 @@ public class SysJobController extends BaseController
@ResponseBody @ResponseBody
public AjaxResult run(SysJob job) throws SchedulerException public AjaxResult run(SysJob job) throws SchedulerException
{ {
jobService.run(job); boolean result = jobService.run(job);
return success(); return result ? success() : error("任务不存在或已过期!");
} }
/** /**

View File

@ -74,7 +74,7 @@ public interface ISysJobService
* @param job * @param job
* @return * @return
*/ */
public void run(SysJob job) throws SchedulerException; public boolean run(SysJob job) throws SchedulerException;
/** /**
* *

View File

@ -177,14 +177,21 @@ public class SysJobServiceImpl implements ISysJobService
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void run(SysJob job) throws SchedulerException public boolean run(SysJob job) throws SchedulerException
{ {
boolean result = false;
Long jobId = job.getJobId(); Long jobId = job.getJobId();
SysJob tmpObj = selectJobById(job.getJobId()); SysJob tmpObj = selectJobById(job.getJobId());
// 参数 // 参数
JobDataMap dataMap = new JobDataMap(); JobDataMap dataMap = new JobDataMap();
dataMap.put(ScheduleConstants.TASK_PROPERTIES, tmpObj); dataMap.put(ScheduleConstants.TASK_PROPERTIES, tmpObj);
scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, tmpObj.getJobGroup()), dataMap); JobKey jobKey = ScheduleUtils.getJobKey(jobId, tmpObj.getJobGroup());
if (scheduler.checkExists(jobKey))
{
result = true;
scheduler.triggerJob(jobKey, dataMap);
}
return result;
} }
/** /**

View File

@ -83,7 +83,12 @@ public class ScheduleUtils
scheduler.deleteJob(getJobKey(jobId, jobGroup)); scheduler.deleteJob(getJobKey(jobId, jobGroup));
} }
scheduler.scheduleJob(jobDetail, trigger); // 判断任务是否过期
if (StringUtils.isNotNull(CronUtils.getNextExecution(job.getCronExpression())))
{
// 执行调度任务
scheduler.scheduleJob(jobDetail, trigger);
}
// 暂停任务 // 暂停任务
if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))