mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 15:24:55 +00:00
29 lines
647 B
TypeScript
29 lines
647 B
TypeScript
import logger from 'CommonServer/Utils/Logger';
|
|
import cron from 'node-cron';
|
|
|
|
const RunCron: Function = (
|
|
jobName: string,
|
|
options: {
|
|
schedule: string;
|
|
runOnStartup: boolean;
|
|
},
|
|
runFunction: Function
|
|
): void => {
|
|
cron.schedule(options.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);
|
|
}
|
|
});
|
|
|
|
if (options.runOnStartup) {
|
|
runFunction();
|
|
}
|
|
};
|
|
|
|
export default RunCron;
|