mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-23 07:42:10 +00:00
37 lines
842 B
TypeScript
37 lines
842 B
TypeScript
import JobDictonary from './JobDictionary';
|
|
import Queue, { QueueName } from 'CommonServer/Infrastructure/Queue';
|
|
import logger from 'CommonServer/Utils/Logger';
|
|
|
|
const RunCron: Function = (
|
|
jobName: string,
|
|
options: {
|
|
schedule: string;
|
|
runOnStartup: boolean;
|
|
},
|
|
runFunction: Function
|
|
): void => {
|
|
JobDictonary.setJobFunction(jobName, runFunction);
|
|
|
|
Queue.addJob(
|
|
QueueName.Worker,
|
|
jobName,
|
|
jobName,
|
|
{},
|
|
{
|
|
scheduleAt: options.schedule,
|
|
}
|
|
).catch((err: Error) => {
|
|
return logger.error(err);
|
|
});
|
|
|
|
if (options.runOnStartup) {
|
|
Queue.addJob(QueueName.Worker, jobName, jobName, {}).catch(
|
|
(err: Error) => {
|
|
return logger.error(err);
|
|
}
|
|
);
|
|
}
|
|
};
|
|
|
|
export default RunCron;
|