Skip to content

Commit

Permalink
#3667 - Bull Scheduler - Updated ioredis and Added Logs (#3989)
Browse files Browse the repository at this point in the history
To proceed with the investigation about the intermittent ioredis issue
on DEV, the package was updated and more logs were added to try to
narrow down the root cause of the issue.
  • Loading branch information
andrewsignori-aot authored Nov 22, 2024
1 parent 238f559 commit 8823c4e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export abstract class BaseScheduler<T> implements OnApplicationBootstrap {
await this.schedulerQueue.obliterate({ force: true });
return;
}
this.logger.log(
`Check if current job state is paused for queue ${this.schedulerQueue.name}.`,
);
// Check if the job is paused to avoid creating new delayed jobs.
const isPaused = await this.schedulerQueue.isPaused();
if (isPaused) {
Expand All @@ -97,7 +100,18 @@ export abstract class BaseScheduler<T> implements OnApplicationBootstrap {
await this.queueService.acquireQueueLock(
this.schedulerQueue.name as QueueNames,
async () => {
await this.ensureNextDelayedJobCreation();
this.logger.log(
`Starting verification to ensure the next delayed job is created for queue ${this.schedulerQueue.name}.`,
);
try {
await this.ensureNextDelayedJobCreation();
} catch (error: unknown) {
this.logger.error(
`Error while ensuring next delayed job for queue ${this.schedulerQueue.name}.`,
error,
);
throw error;
}
},
);
}
Expand All @@ -107,6 +121,9 @@ export abstract class BaseScheduler<T> implements OnApplicationBootstrap {
* next expected scheduled time based on the configured cron expression.
*/
private async ensureNextDelayedJobCreation(): Promise<void> {
this.logger.log(
`Getting list of delayed jobs for queue ${this.schedulerQueue.name}.`,
);
const delayedJobs = await this.schedulerQueue.getDelayed();
const expectedJobMilliseconds =
await this.getNexSchedulerExecutionMilliseconds();
Expand All @@ -123,6 +140,9 @@ export abstract class BaseScheduler<T> implements OnApplicationBootstrap {
// Remove any non expected delayed job.
for (const delayedJob of delayedJobs) {
if (!expectedDelayedJob || delayedJob !== expectedDelayedJob) {
this.logger.log(
`Removing job ${delayedJob.id} from queue ${this.schedulerQueue.name}.`,
);
await delayedJob.remove();
}
}
Expand All @@ -134,9 +154,15 @@ export abstract class BaseScheduler<T> implements OnApplicationBootstrap {
// Creating a unique job ID ensures that the delayed jobs
// will be created even if they were already promoted.
const uniqueJobId = `${this.schedulerQueue.name}:${uuid()}`;
this.logger.log(
`Creating new delayed job using unique id ${uniqueJobId} for queue ${this.schedulerQueue.name}.`,
);
await this.schedulerQueue.add(await this.payload(), {
jobId: uniqueJobId,
});
this.logger.log(
`New delayed job id ${uniqueJobId} was created for queue ${this.schedulerQueue.name}.`,
);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions sources/packages/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sources/packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"dotenv": "^8.2.0",
"express-basic-auth": "^1.2.1",
"helmet": "^7.1.0",
"ioredis": "^5.2.4",
"ioredis": "^5.4.1",
"jsonpath": "^1.1.1",
"jwt-decode": "^3.1.2",
"papaparse": "^5.4.1",
Expand Down

0 comments on commit 8823c4e

Please sign in to comment.