Skip to content

Commit

Permalink
fix(core): Tighten checks for multi-main setup usage (#7788)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Nov 23, 2023
1 parent 6208af0 commit fdb2c18
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
5 changes: 1 addition & 4 deletions packages/cli/src/ActiveWorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import { Service } from 'typedi';
import { ActiveWorkflows, NodeExecuteFunctions } from 'n8n-core';
import config from '@/config';

import type {
ExecutionError,
Expand Down Expand Up @@ -99,9 +98,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
) {}

async init() {
if (config.getEnv('executions.mode') === 'queue' && config.getEnv('multiMainSetup.enabled')) {
await this.multiMainSetup.init();
}
await this.multiMainSetup.init();

await this.addActiveWorkflows('init');

Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export class License {
return;
}

if (config.getEnv('executions.mode') === 'queue' && config.getEnv('multiMainSetup.enabled')) {
await this.multiMainSetup.init();
}
await this.multiMainSetup.init();

const isMainInstance = instanceType === 'main';
const server = config.getEnv('license.serverUrl');
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Start extends BaseCommand {
this.pruningService.stopPruning();
}

if (config.getEnv('executions.mode') === 'queue' && config.getEnv('multiMainSetup.enabled')) {
if (Container.get(MultiMainSetup).isEnabled) {
await this.activeWorkflowRunner.removeAllTriggerAndPollerBasedWorkflows();

await Container.get(MultiMainSetup).shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class MultiMainSetup extends SingleMainSetup {
return (
config.getEnv('executions.mode') === 'queue' &&
config.getEnv('multiMainSetup.enabled') &&
config.getEnv('generic.instanceType') === 'main' &&
this.isLicensed
);
}
Expand All @@ -37,7 +38,7 @@ export class MultiMainSetup extends SingleMainSetup {
private leaderCheckInterval: NodeJS.Timer | undefined;

async init() {
if (this.isInitialized) return;
if (!this.isEnabled || this.isInitialized) return;

await this.initPublisher();

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/services/pruning.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class PruningService {

if (
config.getEnv('multiMainSetup.enabled') &&
config.getEnv('generic.instanceType') === 'main' &&
config.getEnv('multiMainSetup.instanceType') === 'follower'
) {
return false;
Expand Down
20 changes: 9 additions & 11 deletions packages/cli/src/workflows/workflows.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,17 @@ export class WorkflowsService {
}
}

if (config.getEnv('executions.mode') === 'queue' && config.getEnv('multiMainSetup.enabled')) {
const multiMainSetup = Container.get(MultiMainSetup);
const multiMainSetup = Container.get(MultiMainSetup);

await multiMainSetup.init();
await multiMainSetup.init();

if (multiMainSetup.isEnabled) {
await Container.get(MultiMainSetup).broadcastWorkflowActiveStateChanged({
workflowId,
oldState,
newState: updatedWorkflow.active,
versionId: shared.workflow.versionId,
});
}
if (multiMainSetup.isEnabled) {
await Container.get(MultiMainSetup).broadcastWorkflowActiveStateChanged({
workflowId,
oldState,
newState: updatedWorkflow.active,
versionId: shared.workflow.versionId,
});
}

return updatedWorkflow;
Expand Down

0 comments on commit fdb2c18

Please sign in to comment.