定时任务校验

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
frontend/src/business/components

View File

@ -6,8 +6,8 @@
<span class="character" @click="scheduleEdit">SCHEDULER</span> <span class="character" @click="scheduleEdit">SCHEDULER</span>
</span> </span>
<el-switch :disabled="!schedule.value" v-model="schedule.enable" @change="scheduleChange"/> <el-switch :disabled="!schedule.value" v-model="schedule.enable" @change="scheduleChange"/>
<ms-schedule-edit :schedule="schedule" :save="save" ref="scheduleEdit"/> <ms-schedule-edit :schedule="schedule" :save="save" :custom-validate="customValidate" ref="scheduleEdit"/>
<crontab-result v-show="false" :ex="schedule.value" ref="crontabResult" @resultListChange="recentListChange"/> <crontab-result v-show="false" :ex="schedule.value" ref="crontabResult" @resultListChange="resultListChange"/>
</div> </div>
<div> <div>
<span :class="{'disable-character': !schedule.enable}"> 下次执行时间{{this.recentList.length > 0 ? this.recentList[0] : '未设置'}} </span> <span :class="{'disable-character': !schedule.enable}"> 下次执行时间{{this.recentList.length > 0 ? this.recentList[0] : '未设置'}} </span>
@ -18,6 +18,9 @@
<script> <script>
import MsScheduleEdit from "./MsScheduleEdit"; import MsScheduleEdit from "./MsScheduleEdit";
import CrontabResult from "../cron/CrontabResult"; import CrontabResult from "../cron/CrontabResult";
function defaultCustomValidate() {return {pass: true};}
export default { export default {
name: "MsScheduleConfig", name: "MsScheduleConfig",
components: {CrontabResult, MsScheduleEdit}, components: {CrontabResult, MsScheduleEdit},
@ -37,6 +40,10 @@
} }
} }
}, },
customValidate: {
type: Function,
default: defaultCustomValidate
},
}, },
methods: { methods: {
scheduleEdit() { scheduleEdit() {
@ -48,8 +55,11 @@
scheduleChange() { scheduleChange() {
this.$emit('scheduleChange'); this.$emit('scheduleChange');
}, },
recentListChange(resultList) { resultListChange(resultList) {
this.recentList = 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="showCronDialog">生成 Cron</el-button>
<el-button type="primary" @click="saveCron">保存</el-button> <el-button type="primary" @click="saveCron">保存</el-button>
</el-form-item> </el-form-item>
<crontab-result :ex="form.cronValue" ref="crontabResult"/> <crontab-result :ex="form.cronValue" ref="crontabResult" />
</el-form> </el-form>
<el-dialog title="生成 cron" :visible.sync="showCron" :modal="false"> <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> </el-dialog>
</div> </div>
</el-dialog> </el-dialog>
@ -24,12 +24,18 @@
import CrontabResult from "../cron/CrontabResult"; import CrontabResult from "../cron/CrontabResult";
import {cronValidate} from "../../../../common/js/cron"; import {cronValidate} from "../../../../common/js/cron";
function defaultCustomValidate() {return {pass: true};}
export default { export default {
name: "MsScheduleEdit", name: "MsScheduleEdit",
components: {CrontabResult, Crontab}, components: {CrontabResult, Crontab},
props: { props: {
save: Function, save: Function,
schedule: {}, schedule: {},
customValidate: {
type: Function,
default: defaultCustomValidate
},
}, },
watch: { watch: {
'schedule.value'() { 'schedule.value'() {
@ -38,8 +44,13 @@
}, },
data() { data() {
const validateCron = (rule, cronValue, callback) => { const validateCron = (rule, cronValue, callback) => {
let customValidate = this.customValidate(this.getIntervalTime());
if (!cronValidate(cronValue)) { if (!cronValidate(cronValue)) {
callback(new Error('Cron 表达式格式错误')); callback(new Error('Cron 表达式格式错误'));
} else if(!this.intervalShortValidate()) {
callback(new Error('间隔时间请大于 5 分钟'));
} else if (!customValidate.pass){
callback(new Error(customValidate.info));
} else { } else {
callback(); callback();
} }
@ -58,10 +69,12 @@
methods: { methods: {
open() { open() {
this.dialogVisible = true; this.dialogVisible = true;
this.form.cronValue = this.schedule.value;
}, },
crontabFill(value) { crontabFill(value, resultList) {
// //
this.form.cronValue = value; this.form.cronValue = value;
this.$refs.crontabResult.resultList = resultList;
this.$refs['from'].validate(); this.$refs['from'].validate();
}, },
showCronDialog() { showCronDialog() {
@ -78,11 +91,27 @@
}); });
}, },
close() { close() {
this.dialogVisible = false;
this.form.cronValue = ''; this.form.cronValue = '';
this.$refs['from'].resetFields(); this.$refs['from'].resetFields();
if (!this.schedule.value) { if (!this.schedule.value) {
this.$refs.crontabResult.resultList = []; 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> </tbody>
</table> </table>
</div> </div>
<crontab-result :ex="contabValueString"/> <crontab-result :ex="contabValueString" ref="crontabResult"/>
<div class="pop_btn"> <div class="pop_btn">
<el-button size="small" type="primary" @click="submitFill">确定</el-button> <el-button size="small" type="primary" @click="submitFill">确定</el-button>
@ -305,7 +305,7 @@
}, },
// //
submitFill() { submitFill() {
this.$emit("fill", this.contabValueString); this.$emit("fill", this.contabValueString, this.$refs.crontabResult.resultList);
this.hidePopup(); this.hidePopup();
}, },
clearCron() { clearCron() {

View File

@ -10,6 +10,8 @@
</template> </template>
<script> <script>
import {cronValidate} from "../../../../common/js/cron";
export default { export default {
name: 'CrontabResult', name: 'CrontabResult',
data() { data() {
@ -30,11 +32,11 @@ export default {
this.expressionChange(); this.expressionChange();
}, },
methods: { methods: {
// //
expressionChange() { expressionChange() {
// - // -
this.isShow = false; this.isShow = false;
if (!this.ex) { if (!cronValidate(this.ex)) {
this.resultList = []; this.resultList = [];
this.$emit("resultListChange", this.resultList); this.$emit("resultListChange", this.resultList);
return; 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="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> <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-col>
</el-row> </el-row>
@ -278,6 +278,18 @@
return false; return false;
} }
return true; return true;
},
durationValidate(intervalTime) {
let duration = this.$refs.pressureConfig.duration * 60 * 1000;
if (intervalTime < duration) {
return {
pass: false,
info: '间隔时间不能小于压测时长'
}
}
return {
pass: true
}
} }
} }
} }