mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(core): Ensure init
before checking leader or follower in multi-main scenario (#7621)
This PR ensures `MultiMainInstancePublisher` is initialized before checking if the instance is leader or follower. Followers skip license init, license check, and pruning start and stop.
This commit is contained in:
parent
52f655f3d2
commit
a994ba5e8d
|
@ -118,7 +118,11 @@ export class License {
|
||||||
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Container.get(MultiMainInstancePublisher).isFollower) {
|
const multiMainInstancePublisher = Container.get(MultiMainInstancePublisher);
|
||||||
|
|
||||||
|
await multiMainInstancePublisher.init();
|
||||||
|
|
||||||
|
if (multiMainInstancePublisher.isFollower) {
|
||||||
this.logger.debug('Instance is follower, skipping sending of reloadLicense command...');
|
this.logger.debug('Instance is follower, skipping sending of reloadLicense command...');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,11 @@ export abstract class BaseCommand extends Command {
|
||||||
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Container.get(MultiMainInstancePublisher).isFollower) {
|
const multiMainInstancePublisher = Container.get(MultiMainInstancePublisher);
|
||||||
|
|
||||||
|
await multiMainInstancePublisher.init();
|
||||||
|
|
||||||
|
if (multiMainInstancePublisher.isFollower) {
|
||||||
this.logger.debug('Instance is follower, skipping license initialization...');
|
this.logger.debug('Instance is follower, skipping license initialization...');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -269,6 +273,7 @@ export abstract class BaseCommand extends Command {
|
||||||
try {
|
try {
|
||||||
this.logger.debug('Attempting license activation');
|
this.logger.debug('Attempting license activation');
|
||||||
await license.activate(activationKey);
|
await license.activate(activationKey);
|
||||||
|
this.logger.debug('License init complete');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('Could not activate license', e as Error);
|
this.logger.error('Could not activate license', e as Error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ export class Start extends BaseCommand {
|
||||||
this.activeWorkflowRunner = Container.get(ActiveWorkflowRunner);
|
this.activeWorkflowRunner = Container.get(ActiveWorkflowRunner);
|
||||||
|
|
||||||
await this.initLicense();
|
await this.initLicense();
|
||||||
this.logger.debug('License init complete');
|
|
||||||
await this.initOrchestration();
|
await this.initOrchestration();
|
||||||
this.logger.debug('Orchestration init complete');
|
this.logger.debug('Orchestration init complete');
|
||||||
await this.initBinaryDataService();
|
await this.initBinaryDataService();
|
||||||
|
@ -233,15 +233,23 @@ export class Start extends BaseCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Container.get(License).isMultipleMainInstancesLicensed()) {
|
// multi-main scenario
|
||||||
throw new FeatureNotLicensedError(LICENSE_FEATURES.MULTIPLE_MAIN_INSTANCES);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { MultiMainInstancePublisher } = await import(
|
const { MultiMainInstancePublisher } = await import(
|
||||||
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
||||||
);
|
);
|
||||||
|
|
||||||
await Container.get(MultiMainInstancePublisher).init();
|
const multiMainInstancePublisher = Container.get(MultiMainInstancePublisher);
|
||||||
|
|
||||||
|
await multiMainInstancePublisher.init();
|
||||||
|
|
||||||
|
if (
|
||||||
|
multiMainInstancePublisher.isLeader &&
|
||||||
|
!Container.get(License).isMultipleMainInstancesLicensed()
|
||||||
|
) {
|
||||||
|
throw new FeatureNotLicensedError(LICENSE_FEATURES.MULTIPLE_MAIN_INSTANCES);
|
||||||
|
}
|
||||||
|
|
||||||
await Container.get(OrchestrationHandlerMainService).init();
|
await Container.get(OrchestrationHandlerMainService).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ export class MultiMainInstancePublisher extends SingleMainInstancePublisher {
|
||||||
private leaderCheckInterval: NodeJS.Timer | undefined;
|
private leaderCheckInterval: NodeJS.Timer | undefined;
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
if (this.initialized) return;
|
||||||
|
|
||||||
await this.initPublisher();
|
await this.initPublisher();
|
||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
|
|
|
@ -46,7 +46,11 @@ export class PruningService {
|
||||||
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
||||||
);
|
);
|
||||||
|
|
||||||
return Container.get(MultiMainInstancePublisher).isLeader;
|
const multiMainInstancePublisher = Container.get(MultiMainInstancePublisher);
|
||||||
|
|
||||||
|
await multiMainInstancePublisher.init();
|
||||||
|
|
||||||
|
return multiMainInstancePublisher.isLeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -63,7 +67,11 @@ export class PruningService {
|
||||||
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Container.get(MultiMainInstancePublisher).isFollower) return;
|
const multiMainInstancePublisher = Container.get(MultiMainInstancePublisher);
|
||||||
|
|
||||||
|
await multiMainInstancePublisher.init();
|
||||||
|
|
||||||
|
if (multiMainInstancePublisher.isFollower) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.debug('Clearing soft-deletion interval and hard-deletion timeout (pruning cycle)');
|
this.logger.debug('Clearing soft-deletion interval and hard-deletion timeout (pruning cycle)');
|
||||||
|
|
Loading…
Reference in a new issue