Skip to content

Commit

Permalink
fix: Initialize license in queue mode correctly (#6301)
Browse files Browse the repository at this point in the history
  • Loading branch information
krynble committed May 23, 2023
1 parent 55b755c commit 42c79cd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class License {

isFeatureEnabled(feature: string): boolean {
if (!this.manager) {
getLogger().warn('License manager not initialized');
return false;
}

Expand Down
23 changes: 23 additions & 0 deletions packages/cli/src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import type { IExternalHooksClass } from '@/Interfaces';
import { InternalHooks } from '@/InternalHooks';
import { PostHogClient } from '@/posthog';
import { License } from '@/License';

export const UM_FIX_INSTRUCTION =
'Please fix the database by running ./packages/cli/bin/n8n user-management:reset';
Expand Down Expand Up @@ -119,6 +120,28 @@ export abstract class BaseCommand extends Command {
await this.externalHooks.init();
}

async initLicense(): Promise<void> {
const license = Container.get(License);
await license.init(this.instanceId);

const activationKey = config.getEnv('license.activationKey');

if (activationKey) {
const hasCert = (await license.loadCertStr()).length > 0;

if (hasCert) {
return LoggerProxy.debug('Skipping license activation');
}

try {
LoggerProxy.debug('Attempting license activation');
await license.activate(activationKey);
} catch (e) {
LoggerProxy.error('Could not activate license', e as Error);
}
}
}

async finally(error: Error | undefined) {
if (inTest || this.id === 'start') return;
if (Db.connectionState.connected) {
Expand Down
23 changes: 0 additions & 23 deletions packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { EDITOR_UI_DIST_DIR, GENERATED_STATIC_DIR } from '@/constants';
import { eventBus } from '@/eventbus';
import { BaseCommand } from './BaseCommand';
import { InternalHooks } from '@/InternalHooks';
import { License } from '@/License';

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
const open = require('open');
Expand Down Expand Up @@ -186,28 +185,6 @@ export class Start extends BaseCommand {
await Promise.all(files.map(compileFile));
}

async initLicense(): Promise<void> {
const license = Container.get(License);
await license.init(this.instanceId);

const activationKey = config.getEnv('license.activationKey');

if (activationKey) {
const hasCert = (await license.loadCertStr()).length > 0;

if (hasCert) {
return LoggerProxy.debug('Skipping license activation');
}

try {
LoggerProxy.debug('Attempting license activation');
await license.activate(activationKey);
} catch (e) {
LoggerProxy.error('Could not activate license', e as Error);
}
}
}

async init() {
await this.initCrashJournal();

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class Webhook extends BaseCommand {
await this.initCrashJournal();
await super.init();

await this.initLicense();
await this.initBinaryManager();
await this.initExternalHooks();
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class Worker extends BaseCommand {
await super.init();
this.logger.debug('Starting n8n worker...');

await this.initLicense();
await this.initBinaryManager();
await this.initExternalHooks();
}
Expand Down

0 comments on commit 42c79cd

Please sign in to comment.