45 lines
1.5 KiB
Java
45 lines
1.5 KiB
Java
package com.ruoyi.quartz.util;
|
|
|
|
import org.quartz.CronScheduleBuilder;
|
|
import org.quartz.CronTrigger;
|
|
import org.quartz.Job;
|
|
import org.quartz.JobBuilder;
|
|
import org.quartz.JobDetail;
|
|
import org.quartz.JobKey;
|
|
import org.quartz.Scheduler;
|
|
import org.quartz.SchedulerException;
|
|
import org.quartz.TriggerBuilder;
|
|
import org.quartz.TriggerKey;
|
|
import com.ruoyi.common.constant.ScheduleConstants;
|
|
import com.ruoyi.common.exception.job.TaskException;
|
|
import com.ruoyi.common.exception.job.TaskException.Code;
|
|
import com.ruoyi.quartz.domain.SysJob;
|
|
|
|
/**
|
|
* 定时任务工具类
|
|
*
|
|
* @author ruoyi
|
|
*/
|
|
public class ScheduleUtils {
|
|
|
|
/**
|
|
* 设置定时任务策略
|
|
*/
|
|
public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
|
|
throws TaskException {
|
|
switch (job.getMisfirePolicy()) {
|
|
case ScheduleConstants.MISFIRE_DEFAULT:
|
|
return cb;
|
|
case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
|
|
return cb.withMisfireHandlingInstructionIgnoreMisfires();
|
|
case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
|
|
return cb.withMisfireHandlingInstructionFireAndProceed();
|
|
case ScheduleConstants.MISFIRE_DO_NOTHING:
|
|
return cb.withMisfireHandlingInstructionDoNothing();
|
|
default:
|
|
throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
|
|
+ "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
|
|
}
|
|
}
|
|
}
|