Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Block all queue operations until the queue is ready (no-changelog) #11278

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/src/executions/execution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ export class ExecutionService {

const { ScalingService } = await import('@/scaling/scaling.service');
const scalingService = Container.get(ScalingService);
await scalingService.queueReady;
const jobs = await scalingService.findJobsByStatus(['active', 'waiting']);

const job = jobs.find(({ data }) => data.executionId === execution.id);
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/scaling/scaling.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
jsonStringify,
ErrorReporterProxy,
ensureError,
createDeferredPromise,
} from 'n8n-workflow';
import type { IExecuteResponsePromiseData } from 'n8n-workflow';
import { strict } from 'node:assert';
Expand Down Expand Up @@ -41,6 +42,8 @@ import type {
export class ScalingService {
private queue: JobQueue;

private queueReadyPromise = createDeferredPromise();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could replace private queue: JobQueue with private queuePromise: Promise<JobQueue> and use that everywhere so we don't have to keep the queue and its promise separately?


constructor(
private readonly logger: Logger,
private readonly activeExecutions: ActiveExecutions,
Expand All @@ -54,6 +57,10 @@ export class ScalingService {
this.logger = this.logger.withScope('scaling');
}

get queueReady() {
return this.queueReadyPromise.promise;
}

// #region Lifecycle

async setupQueue() {
Expand Down Expand Up @@ -81,6 +88,7 @@ export class ScalingService {
}

this.scheduleQueueMetrics();
this.queueReadyPromise.resolve();

this.logger.debug('Queue setup completed');
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/workflow-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export class WorkflowRunner {
if (!this.scalingService) {
const { ScalingService } = await import('@/scaling/scaling.service');
this.scalingService = Container.get(ScalingService);
await this.scalingService.queueReady;
}

// TODO: For realtime jobs should probably also not do retry or not retry if they are older than x seconds.
Expand Down