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): Ensure init before checking leader or follower in multi-main scenario #7621

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
6 changes: 5 additions & 1 deletion packages/cli/src/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export class License {
'@/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...');
return;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ export abstract class BaseCommand extends Command {
'@/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...');
return;
}
Expand All @@ -269,6 +273,7 @@ export abstract class BaseCommand extends Command {
try {
this.logger.debug('Attempting license activation');
await license.activate(activationKey);
this.logger.debug('License init complete');
} catch (e) {
this.logger.error('Could not activate license', e as Error);
}
Expand Down
18 changes: 13 additions & 5 deletions packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class Start extends BaseCommand {
this.activeWorkflowRunner = Container.get(ActiveWorkflowRunner);

await this.initLicense();
this.logger.debug('License init complete');

await this.initOrchestration();
this.logger.debug('Orchestration init complete');
await this.initBinaryDataService();
Expand All @@ -233,15 +233,23 @@ export class Start extends BaseCommand {
return;
}

if (!Container.get(License).isMultipleMainInstancesLicensed()) {
throw new FeatureNotLicensedError(LICENSE_FEATURES.MULTIPLE_MAIN_INSTANCES);
}
// multi-main scenario

const { MultiMainInstancePublisher } = await import(
'@/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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class MultiMainInstancePublisher extends SingleMainInstancePublisher {
private leaderCheckInterval: NodeJS.Timer | undefined;

async init() {
if (this.initialized) return;

await this.initPublisher();

this.initialized = true;
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/services/pruning.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export class PruningService {
'@/services/orchestration/main/MultiMainInstance.publisher.ee'
);

return Container.get(MultiMainInstancePublisher).isLeader;
const multiMainInstancePublisher = Container.get(MultiMainInstancePublisher);

await multiMainInstancePublisher.init();

return multiMainInstancePublisher.isLeader;
}

return true;
Expand All @@ -63,7 +67,11 @@ export class PruningService {
'@/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)');
Expand Down
Loading