新增 - 完善计划任务辅助器

This commit is contained in:
suwings 2018-06-02 09:57:57 +08:00
parent ff75380386
commit 6e3aa9c6cd

View File

@ -3,7 +3,7 @@ const schedule = require("node-schedule");
MCSERVER.Schedule = {};
MCSERVER.Schedule.container = {};
//循环型任务
module.exports.createScheduleJob = (id, time, callback) => {
let mask = MCSERVER.Schedule.container[id] = schedule.scheduleJob(time, (fireDate) => {
let res = callback();
@ -13,9 +13,7 @@ module.exports.createScheduleJob = (id, time, callback) => {
});
}
//计次型任务
module.exports.createScheduleJobCount = (id, time, callback, count) => {
let lco = 0;
let mask = MCSERVER.Schedule.container[id] = schedule.scheduleJob(time, (fireDate) => {
@ -29,4 +27,12 @@ module.exports.createScheduleJobCount = (id, time, callback, count) => {
mask.cancel();
}
});
}
//删除
module.exports.deleteScheduleJob = (id) => {
let mask = MCSERVER.Schedule.container[id] || null;
if (mask) {
mask.cancel();
}
}