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

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

View File

@@ -1497,3 +1497,4 @@ validate_error=Unexpected error occurred while validating
is_schduler=Scheduler is_schduler=Scheduler
v4_num=IPv4 Number v4_num=IPv4 Number
v6_num=IPv6 Number v6_num=IPv6 Number
always=Permanent

View File

@@ -1502,3 +1502,4 @@ is_schduler=Scheduler
validate_error=Unexpected error occurred while validating validate_error=Unexpected error occurred while validating
v4_num=IPv4 Number v4_num=IPv4 Number
v6_num=IPv6 Number v6_num=IPv6 Number
always=\u041F\u043E\u0441\u0442\u043E\u044F\u043D\u043D\u043E

View File

@@ -1493,4 +1493,5 @@ everyWeek=\u6BCF\u5468
everyMonth=\u6BCF\u6708 everyMonth=\u6BCF\u6708
validate_error=\u9A8C\u8BC1\u65F6\u53D1\u751F\u610F\u5916\u9519\u8BEF validate_error=\u9A8C\u8BC1\u65F6\u53D1\u751F\u610F\u5916\u9519\u8BEF
v4_num=IPv4 Number v4_num=IPv4 Number
v6_num=IPv6 Number v6_num=IPv6 Number
always=\u957F\u671F

View File

@@ -5,7 +5,10 @@
margin-bottom: 10px; margin-bottom: 10px;
} }
.detail{ .detail{
border-left: 2px solid #999; /* border-left: 1px solid #999; */
}
.mode{
border-right: 1px solid #999;
} }
</style> </style>
@@ -95,7 +98,12 @@
<div class="col-md-1 mode"><!-- 一次,每天,每周,每月选择 --> <div class="col-md-1 mode"><!-- 一次,每天,每周,每月选择 -->
<div class="form-group"> <div class="form-group">
<label class="radio-inline"> <label class="radio-inline">
<input id="single" type="radio" class="required every" name="schedule.userRegion1" value="single" checked="checked" <c:if test="${_cfg.schedule.userRegion1 == 'single' }">checked="checked"</c:if>><spring:message code="single"/> <input id="always" type="radio" class="required every" name="schedule.userRegion1" value="always" checked="checked" <c:if test="${_cfg.schedule.userRegion1 == 'always' }">checked="checked"</c:if>><spring:message code="always"/>
</label>
</div>
<div class="form-group">
<label class="radio-inline">
<input id="single" type="radio" class="required every" name="schedule.userRegion1" value="single" <c:if test="${_cfg.schedule.userRegion1 == 'single' }">checked="checked"</c:if>><spring:message code="single"/>
</label> </label>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -116,7 +124,24 @@
</div> </div>
<div class="col-md-9 detail"> <div class="col-md-9 detail">
<!-- 一次执行 --> <!-- 一次执行 -->
<div class="single"> <div class="always">
<div class="form-group ">
<label class="control-label col-md-2"><spring:message code="startTime"/></label>
<div class="col-md-4">
<input name="schedule.cronValid" id="alwaysValid" type="text" class="form-control Wdate required" readonly="readonly" value="${_cfg.schedule.cronValid }" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true,minDate:'%y-%M-%d %H:{%m+2}:%s'});"/>
</div>
<div for="schedule.cronValid"></div>
</div>
<%-- <div class="form-group ">
<label class="control-label col-md-2"><spring:message code="endTime"/></label>
<div class="col-md-4">
<input name="schedule.cronInvalid" id="singleInvalid" type="text" class="form-control Wdate required" readonly="readonly" value="${_cfg.schedule.cronInvalid }" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true,minDate:'#F{$dp.$D(\'singleValid\')}'});"/>
</div>
<div for="schedule.cronInvalid"></div>
</div> --%>
</div>
<!-- 一次执行 -->
<div class="single hidden">
<div class="form-group "> <div class="form-group ">
<label class="control-label col-md-2"><spring:message code="startTime"/></label> <label class="control-label col-md-2"><spring:message code="startTime"/></label>
<div class="col-md-4"> <div class="col-md-4">

View File

@@ -18,7 +18,7 @@
function init(){ function init(){
//初始化 mode 模式,一次,每天,每周,每月 //初始化 mode 模式,一次,每天,每周,每月
$("div.cronContain ").each(function(i,n){ $("div.cronContain_${index } ").each(function(i,n){
var $this = $(this); var $this = $(this);
var mode = $this.find("input.every:checked").val(); var mode = $this.find("input.every:checked").val();
@@ -31,10 +31,10 @@
$this.find(".detail > div").not("."+mode).find("select").val(""); $this.find(".detail > div").not("."+mode).find("select").val("");
$this.find("input").attr("disabled","disabled").attr("name",function(){ $this.find("input").attr("disabled","disabled").attr("name",function(){
return $(this).attr("name") + i; return $(this).attr("name") + ${index };
}); });
$this.find("select").attr("disabled","disabled").attr("name",function(){ $this.find("select").attr("disabled","disabled").attr("name",function(){
return $(this).attr("name") + i; return $(this).attr("name") + ${index };
}); });
$this.find("input[type='radio']:not(:checked)").closest(".form-group").remove(); $this.find("input[type='radio']:not(:checked)").closest(".form-group").remove();
@@ -50,11 +50,16 @@
</script> </script>
<div id="cron" class=' cronContain row <c:if test="${empty _cfg.schedule }">hidden</c:if>' > <div id="cron" class=' cronContain_${index } row <c:if test="${empty _cfg.schedule }">hidden</c:if>' >
<div class="col-md-1 mode"><!-- 一次,每天,每周,每月选择 --> <div class="col-md-1 mode"><!-- 一次,每天,每周,每月选择 -->
<div class="form-group"> <div class="form-group">
<label class="radio-inline"> <label class="radio-inline">
<input id="single" type="radio" class="required every" name="schedule.userRegion1" value="single" checked="checked" <c:if test="${_cfg.schedule.userRegion1 == 'single' }">checked="checked"</c:if>><spring:message code="single"/> <input id="always" type="radio" class="required every" name="schedule.userRegion1" value="always" checked="checked" <c:if test="${_cfg.schedule.userRegion1 == 'always' }">checked="checked"</c:if>><spring:message code="always"/>
</label>
</div>
<div class="form-group">
<label class="radio-inline">
<input id="single" type="radio" class="required every" name="schedule.userRegion1" value="single" <c:if test="${_cfg.schedule.userRegion1 == 'single' }">checked="checked"</c:if>><spring:message code="single"/>
</label> </label>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -74,8 +79,23 @@
</div> </div>
</div> </div>
<div class="col-md-9 detail"> <div class="col-md-9 detail">
<!-- 一次执行,长期生效 -->
<div class="always">
<div class="form-group row">
<label class="control-label col-md-1"><spring:message code="startTime"/></label>
<div class="col-md-4">
<input name="schedule.cronValid" type="text" class="form-control Wdate required" readonly="readonly" value="${_cfg.schedule.cronValid }" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
</div>
</div>
<%-- <div class="form-group row">
<label class="control-label col-md-1"><spring:message code="endTime"/></label>
<div class="col-md-4">
<input name="schedule.cronInvalid" type="text" class="form-control Wdate required" readonly="readonly" value="${_cfg.schedule.cronInvalid }" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
</div>
</div> --%>
</div>
<!-- 一次执行 --> <!-- 一次执行 -->
<div class="single"> <div class="single hidden">
<div class="form-group row"> <div class="form-group row">
<label class="control-label col-md-1"><spring:message code="startTime"/></label> <label class="control-label col-md-1"><spring:message code="startTime"/></label>
<div class="col-md-4"> <div class="col-md-4">