Skip to content

Commit

Permalink
Merge branch 'master' of github.com:OneUptime/oneuptime
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Sep 6, 2024
2 parents ec4268c + 2c49b8b commit e074633
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions App/FeatureSet/Workers/Utils/Cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Telemetry, {
SpanStatusCode,
} from "Common/Server/Utils/Telemetry";

// Define the function type RunCronFunction
type RunCronFunction = (
jobName: string,
options: {
Expand All @@ -18,6 +19,7 @@ type RunCronFunction = (
runFunction: PromiseVoidFunction,
) => void;

// Implement the RunCron function
const RunCron: RunCronFunction = (
jobName: string,
options: {
Expand All @@ -27,6 +29,7 @@ const RunCron: RunCronFunction = (
},
runFunction: PromiseVoidFunction,
): void => {
// Start a telemetry span for the RunCron operation
return Telemetry.startActiveSpan<void>({
name: "RunCron",
options: {
Expand All @@ -38,14 +41,17 @@ const RunCron: RunCronFunction = (
},
fn: (span: Span): void => {
try {
// Set the job function in JobDictionary
JobDictionary.setJobFunction(jobName, runFunction);

// Set the timeout if provided
if (options.timeoutInMS) {
JobDictionary.setTimeoutInMs(jobName, options.timeoutInMS);
}

logger.debug("Adding job to the queue: " + jobName);

// Add the job to the queue with the specified schedule
Queue.addJob(
QueueName.Worker,
jobName,
Expand All @@ -58,6 +64,7 @@ const RunCron: RunCronFunction = (
return logger.error(err);
});

// Run the job immediately on startup if specified
if (options.runOnStartup) {
Queue.addJob(QueueName.Worker, jobName, jobName, {}, {}).catch(
(err: Error) => {
Expand Down

0 comments on commit e074633

Please sign in to comment.