oneuptime/Workers/Utils/Cron.ts

18 lines
490 B
TypeScript
Raw Normal View History

2022-10-20 11:32:19 +00:00
import logger from 'CommonServer/Utils/Logger';
import cron from 'node-cron';
const RunCron = (jobName: string, schedule: string, runFunction: Function) => {
cron.schedule(schedule, async () => {
try {
logger.info(`Job ${jobName} Start`);
await runFunction();
logger.info(`Job ${jobName} End`);
} catch (e) {
logger.info(`Job ${jobName} Error`);
logger.error(e);
}
});
2022-11-02 17:40:04 +00:00
};
2022-10-20 11:32:19 +00:00
2022-11-02 17:40:04 +00:00
export default RunCron;