ggs-cron/cron-jobs.js
2025-08-06 16:01:57 +07:00

37 lines
1.2 KiB
JavaScript

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,
};