定时任务校验

This commit is contained in:
chenjianxing 2020-06-28 14:02:31 +08:00
parent 22c1858846
commit 0ed718c214
5 changed files with 64 additions and 11 deletions

View File

@ -6,8 +6,8 @@
<span class="character" @click="scheduleEdit">SCHEDULER</span>
</span>
<el-switch :disabled="!schedule.value" v-model="schedule.enable" @change="scheduleChange"/>
<ms-schedule-edit :schedule="schedule" :save="save" ref="scheduleEdit"/>
<crontab-result v-show="false" :ex="schedule.value" ref="crontabResult" @resultListChange="recentListChange"/>
<ms-schedule-edit :schedule="schedule" :save="save" :custom-validate="customValidate" ref="scheduleEdit"/>
<crontab-result v-show="false" :ex="schedule.value" ref="crontabResult" @resultListChange="resultListChange"/>
</div>
<div>
<span :class="{'disable-character': !schedule.enable}"> 下次执行时间{{this.recentList.length > 0 ? this.recentList[0] : '未设置'}} </span>
@ -18,6 +18,9 @@
<script>
import MsScheduleEdit from "./MsScheduleEdit";
import CrontabResult from "../cron/CrontabResult";
function defaultCustomValidate() {return {pass: true};}
export default {
name: "MsScheduleConfig",
components: {CrontabResult, MsScheduleEdit},
@ -37,6 +40,10 @@
}
}
},
customValidate: {
type: Function,
default: defaultCustomValidate
},
},
methods: {
scheduleEdit() {
@ -48,8 +55,11 @@
scheduleChange() {
this.$emit('scheduleChange');
},
recentListChange(resultList) {
resultListChange(resultList) {
this.recentList = resultList;
},
flashResultList() {
this.$refs.crontabResult.expressionChange();
}
}
}

View File

@ -9,10 +9,10 @@
<el-button type="primary" @click="showCronDialog">生成 Cron</el-button>
<el-button type="primary" @click="saveCron">保存</el-button>
</el-form-item>
<crontab-result :ex="form.cronValue" ref="crontabResult"/>
<crontab-result :ex="form.cronValue" ref="crontabResult" />
</el-form>
<el-dialog title="生成 cron" :visible.sync="showCron" :modal="false">
<crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value"/>
<crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value" ref="crontab"/>
</el-dialog>
</div>
</el-dialog>
@ -24,12 +24,18 @@
import CrontabResult from "../cron/CrontabResult";
import {cronValidate} from "../../../../common/js/cron";
function defaultCustomValidate() {return {pass: true};}
export default {
name: "MsScheduleEdit",
components: {CrontabResult, Crontab},
props: {
save: Function,
schedule: {},
customValidate: {
type: Function,
default: defaultCustomValidate
},
},
watch: {
'schedule.value'() {
@ -38,8 +44,13 @@
},
data() {
const validateCron = (rule, cronValue, callback) => {
let customValidate = this.customValidate(this.getIntervalTime());
if (!cronValidate(cronValue)) {
callback(new Error('Cron 表达式格式错误'));
} else if(!this.intervalShortValidate()) {
callback(new Error('间隔时间请大于 5 分钟'));
} else if (!customValidate.pass){
callback(new Error(customValidate.info));
} else {
callback();
}
@ -58,10 +69,12 @@
methods: {
open() {
this.dialogVisible = true;
this.form.cronValue = this.schedule.value;
},
crontabFill(value) {
crontabFill(value, resultList) {
//
this.form.cronValue = value;
this.$refs.crontabResult.resultList = resultList;
this.$refs['from'].validate();
},
showCronDialog() {
@ -78,11 +91,27 @@
});
},
close() {
this.dialogVisible = false;
this.form.cronValue = '';
this.$refs['from'].resetFields();
if (!this.schedule.value) {
this.$refs.crontabResult.resultList = [];
}
},
intervalShortValidate() {
if (this.getIntervalTime() < 5*60*1000) {
return false;
}
return true;
},
resultListChange() {
this.$refs['from'].validate();
},
getIntervalTime() {
let resultList = this.$refs.crontabResult.resultList;
let time1 = new Date(resultList[0]);
let time2 = new Date(resultList[1]);
return time2 - time1;
}
}
}

View File

@ -98,7 +98,7 @@
</tbody>
</table>
</div>
<crontab-result :ex="contabValueString"/>
<crontab-result :ex="contabValueString" ref="crontabResult"/>
<div class="pop_btn">
<el-button size="small" type="primary" @click="submitFill">确定</el-button>
@ -305,7 +305,7 @@
},
//
submitFill() {
this.$emit("fill", this.contabValueString);
this.$emit("fill", this.contabValueString, this.$refs.crontabResult.resultList);
this.hidePopup();
},
clearCron() {

View File

@ -10,6 +10,8 @@
</template>
<script>
import {cronValidate} from "../../../../common/js/cron";
export default {
name: 'CrontabResult',
data() {
@ -30,11 +32,11 @@ export default {
this.expressionChange();
},
methods: {
//
//
expressionChange() {
// -
this.isShow = false;
if (!this.ex) {
if (!cronValidate(this.ex)) {
this.resultList = [];
this.$emit("resultListChange", this.resultList);
return;

View File

@ -24,7 +24,7 @@
<el-button :disabled="isReadOnly" type="primary" plain @click="saveAndRun">{{$t('load_test.save_and_run')}}</el-button>
<el-button :disabled="isReadOnly" type="warning" plain @click="cancel">{{$t('commons.cancel')}}</el-button>
<ms-schedule-config :schedule="testPlan.schedule" :save="saveCronExpression" @scheduleChange="saveSchedule" :check-open="checkScheduleEdit"/>
<ms-schedule-config :schedule="testPlan.schedule" :save="saveCronExpression" @scheduleChange="saveSchedule" :check-open="checkScheduleEdit" :custom-validate="durationValidate"/>
</el-col>
</el-row>
@ -278,6 +278,18 @@
return false;
}
return true;
},
durationValidate(intervalTime) {
let duration = this.$refs.pressureConfig.duration * 60 * 1000;
if (intervalTime < duration) {
return {
pass: false,
info: '间隔时间不能小于压测时长'
}
}
return {
pass: true
}
}
}
}