const config = require("./config"); const cron = require("node-cron"); const { Log } = require("./lib/common"); // CRON JOB GUIDE // # ┌────────────── วินาที (optional) // # │ ┌──────────── นาที // # │ │ ┌────────── ชั่วโมง // # │ │ │ ┌──────── วันที่ // # │ │ │ │ ┌────── เดือน // # │ │ │ │ │ ┌──── วันในสัปดาห์นั้น ๆ // # │ │ │ │ │ │ // # │ │ │ │ │ │ // # * * * * * * const CronScheduleList = { everyMin: "* * * * *", midNight: "0 0 * * *", }; const CronJobs = { MAXIMUM_CRON_JOBS: -1, getAllRunning: cron.getTasks(), doEveryMinute: (task, id) => { if(config.DEBUG) Log.debug(`verify cron ${cron.validate(CronScheduleList.everyMin)}`); return cron.schedule(CronScheduleList.everyMin, task, { name: id }); }, doEveryMidnight: (task, id) => { if(config.DEBUG) Log.debug(`verify cron ${cron.validate(CronScheduleList.midNight)}`); return cron.schedule(CronScheduleList.midNight, task, { name: id }); }, }; module.exports = { CronJobs, };