fix(core): Add check that queue is defined and remove cyclic dependency (#7404)

In a rare edge case an undefined queue could be returned - this should
not happen and now an error is thrown.
Also using the opportunity to remove a cyclic dependency from the Queue.
This commit is contained in:
Michael Auerswald
2023-10-13 11:53:59 +02:00
committed by GitHub
parent 609f0837cf
commit 45f2ef373e
5 changed files with 49 additions and 33 deletions

View File

@@ -2,7 +2,8 @@ import type Bull from 'bull';
import { Service } from 'typedi';
import type { ExecutionError, IExecuteResponsePromiseData } from 'n8n-workflow';
import { ActiveExecutions } from '@/ActiveExecutions';
import * as WebhookHelpers from '@/WebhookHelpers';
import { decodeWebhookResponse } from '@/helpers/decodeWebhookResponse';
import {
getRedisClusterClient,
getRedisClusterNodes,
@@ -62,7 +63,7 @@ export class Queue {
this.jobQueue.on('global:progress', (jobId, progress: WebhookResponse) => {
this.activeExecutions.resolveResponsePromise(
progress.executionId,
WebhookHelpers.decodeWebhookResponse(progress.response),
decodeWebhookResponse(progress.response),
);
});
}
@@ -79,7 +80,23 @@ export class Queue {
return this.jobQueue.getJobs(jobTypes);
}
async process(concurrency: number, fn: Bull.ProcessCallbackFunction<JobData>): Promise<void> {
return this.jobQueue.process(concurrency, fn);
}
async ping(): Promise<string> {
return this.jobQueue.client.ping();
}
async pause(isLocal?: boolean): Promise<void> {
return this.jobQueue.pause(isLocal);
}
getBullObjectInstance(): JobQueue {
if (this.jobQueue === undefined) {
// if queue is not initialized yet throw an error, since we do not want to hand around an undefined queue
throw new Error('Queue is not initialized yet!');
}
return this.jobQueue;
}