定时器增加长期生效选项,长期生效只有生效时间【开始时间】,无失效时间【结束时间】。

This commit is contained in:
zhangwei
2019-01-29 14:25:09 +06:00
parent 0ebee67507
commit 2dadd96484
6 changed files with 96 additions and 35 deletions

View File

@@ -191,6 +191,9 @@ public class ScheduleCfgJob implements Job {
String mode = cfg.getUserRegion1().toUpperCase();//定时任务运行模式:一次,每天,每周,每月
List<Trigger> triList = null;
switch (mode) {
case "ALWAYS"://单次运行,但只创建单次生效触发器
triList = createSimpleTrigger(cfg);
break;
case "SINGLE"://单次运行
triList = createSimpleTrigger(cfg);
break;
@@ -254,32 +257,42 @@ public class ScheduleCfgJob implements Job {
Integer compileId = cfg.getCompileId();
String cronValid = cfg.getCronValid();
String cronInvalid = cfg.getCronInvalid();
Date validDate = DateUtil.convertStringToDate(cronValid, Constants.COMMON_DATE_FORMAT);
Date invalidDate = DateUtil.convertStringToDate(cronInvalid, Constants.COMMON_DATE_FORMAT);
Date validDate = null;
Date invalidDate = null;
if(StringUtils.isNotBlank(cronValid)){
validDate = DateUtil.convertStringToDate(cronValid, Constants.COMMON_DATE_FORMAT);
}
if(StringUtils.isNotBlank(cronInvalid)){
invalidDate = DateUtil.convertStringToDate(cronInvalid, Constants.COMMON_DATE_FORMAT);
}
JobDataMap dataMap = new JobDataMap();
dataMap.put("isValid", true);
dataMap.put("cfg", cfg);
String triName = VALID_KEY + cfg.getUserRegion1() + "_" + cronValid;
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(createTiggerKey(triName, STATUS_GROUP+compileId))
.withSchedule(SimpleScheduleBuilder.simpleSchedule())
.usingJobData(dataMap)
.forJob(STATUS_JOBDETAIL)
.startAt(validDate)
.build();
triList.add(trigger);
dataMap = new JobDataMap();
dataMap.put("isValid", false);
dataMap.put("cfg", cfg);
triName = INVALID_KEY + cfg.getUserRegion1() + "_" + cronInvalid;
trigger = TriggerBuilder.newTrigger()
.withIdentity(createTiggerKey(triName, STATUS_GROUP+compileId))
.withSchedule(SimpleScheduleBuilder.simpleSchedule())
.usingJobData(dataMap)
.forJob(STATUS_JOBDETAIL)
.startAt(invalidDate)
.build();
triList.add(trigger);
if(validDate!=null){//生效时间如果不为空,则创建定时生效触发器
dataMap.put("isValid", true);
dataMap.put("cfg", cfg);
String triName = VALID_KEY + cfg.getUserRegion1() + "_" + cronValid;
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(createTiggerKey(triName, STATUS_GROUP+compileId))
.withSchedule(SimpleScheduleBuilder.simpleSchedule())
.usingJobData(dataMap)
.forJob(STATUS_JOBDETAIL)
.startAt(validDate)
.build();
triList.add(trigger);
}
if(invalidDate!=null){//失效时间如果不为空,则创建定时失效触发器
dataMap = new JobDataMap();
dataMap.put("isValid", false);
dataMap.put("cfg", cfg);
String triName = INVALID_KEY + cfg.getUserRegion1() + "_" + cronInvalid;
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(createTiggerKey(triName, STATUS_GROUP+compileId))
.withSchedule(SimpleScheduleBuilder.simpleSchedule())
.usingJobData(dataMap)
.forJob(STATUS_JOBDETAIL)
.startAt(invalidDate)
.build();
triList.add(trigger);
}
return triList;
}