mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	优化任务过期不执行调度
This commit is contained in:
		@@ -167,8 +167,8 @@ public class SysJobController extends BaseController
 | 
			
		||||
    @PutMapping("/run")
 | 
			
		||||
    public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
 | 
			
		||||
    {
 | 
			
		||||
        jobService.run(job);
 | 
			
		||||
        return AjaxResult.success();
 | 
			
		||||
        boolean result = jobService.run(job);
 | 
			
		||||
        return result ? success() : error("任务不存在或已过期!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -180,6 +180,6 @@ public class SysJobController extends BaseController
 | 
			
		||||
    public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
 | 
			
		||||
    {
 | 
			
		||||
        jobService.deleteJobByIds(jobIds);
 | 
			
		||||
        return AjaxResult.success();
 | 
			
		||||
        return success();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -74,7 +74,7 @@ public interface ISysJobService
 | 
			
		||||
     * @param job 调度信息
 | 
			
		||||
     * @return 结果
 | 
			
		||||
     */
 | 
			
		||||
    public void run(SysJob job) throws SchedulerException;
 | 
			
		||||
    public boolean run(SysJob job) throws SchedulerException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 新增任务
 | 
			
		||||
 
 | 
			
		||||
@@ -174,15 +174,22 @@ public class SysJobServiceImpl implements ISysJobService
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    @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();
 | 
			
		||||
        String jobGroup = job.getJobGroup();
 | 
			
		||||
        SysJob properties = selectJobById(job.getJobId());
 | 
			
		||||
        // 参数
 | 
			
		||||
        JobDataMap dataMap = new JobDataMap();
 | 
			
		||||
        dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
 | 
			
		||||
        scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap);
 | 
			
		||||
        JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
 | 
			
		||||
        if (scheduler.checkExists(jobKey))
 | 
			
		||||
        {
 | 
			
		||||
            result = true;
 | 
			
		||||
            scheduler.triggerJob(jobKey, dataMap);
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,12 @@ public class ScheduleUtils
 | 
			
		||||
            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()))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user