From 6e3aa9c6cd138f17200329ae0b4296dc40b230d3 Mon Sep 17 00:00:00 2001 From: suwings Date: Sat, 2 Jun 2018 09:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20-=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1=E8=BE=85=E5=8A=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/Schedule.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/helper/Schedule.js b/helper/Schedule.js index 4f9ff34..e44da43 100644 --- a/helper/Schedule.js +++ b/helper/Schedule.js @@ -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(); + } } \ No newline at end of file