설치
$npm i node-schedule --save
node-schedule - npm (npmjs.com)
node-schedule.js
const schedule = require("node-schedule"); let sheduleObj = null const set = (s) => { const rule = new schedule.RecurrenceRule(); // rule.dayOfWeek = [0, 1, 2, 3, 4, 5, 6]; //일요일(0), 월요일(1), 화요일(2), 수요일(3),목요일(4), 금요일(5), 토요일(6) rule.dayOfWeek = s.dayOfWeek; rule.hour = s.hour; rule.minute = s.minute; const job = schedule.scheduleJob(rule, function () { console.log('Schedule start!'); }); sheduleObj = job; }; const cancel = () => { if (sheduleObj != null) { sheduleObj.cancel(); } }; const setSchedueler = (s) => { cancel(); set(s); }; const scheduleData = { dayOfWeek: [0, 1, 2, 3, 4, 5, 6], hour: 20, minute: 36 } setSchedueler(scheduleData); module.exports = router;
실행
$ node node-schedule.js
참조:
댓글 ( 5)
댓글 남기기