diff --git a/packages/cli/src/__tests__/license.test.ts b/packages/cli/src/__tests__/license.test.ts index 051378a58d..addbd3bc12 100644 --- a/packages/cli/src/__tests__/license.test.ts +++ b/packages/cli/src/__tests__/license.test.ts @@ -60,6 +60,7 @@ describe('License', () => { loadCertStr: expect.any(Function), saveCertStr: expect.any(Function), onFeatureChange: expect.any(Function), + onLicenseRenewed: expect.any(Function), collectUsageMetrics: expect.any(Function), collectPassthroughData: expect.any(Function), server: MOCK_SERVER_URL, @@ -90,6 +91,7 @@ describe('License', () => { loadCertStr: expect.any(Function), saveCertStr: expect.any(Function), onFeatureChange: expect.any(Function), + onLicenseRenewed: expect.any(Function), collectUsageMetrics: expect.any(Function), collectPassthroughData: expect.any(Function), server: MOCK_SERVER_URL, diff --git a/packages/cli/src/license.ts b/packages/cli/src/license.ts index 623605a0ef..087ed626e3 100644 --- a/packages/cli/src/license.ts +++ b/packages/cli/src/license.ts @@ -10,7 +10,7 @@ import { import { SettingsRepository } from '@n8n/db'; import { OnLeaderStepdown, OnLeaderTakeover, OnShutdown } from '@n8n/decorators'; import { Container, Service } from '@n8n/di'; -import type { TEntitlement, TFeatures, TLicenseBlock } from '@n8n_io/license-sdk'; +import type { TEntitlement, TLicenseBlock } from '@n8n_io/license-sdk'; import { LicenseManager } from '@n8n_io/license-sdk'; import { InstanceSettings, Logger } from 'n8n-core'; @@ -66,7 +66,10 @@ export class License implements LicenseProvider { ? async (value: TLicenseBlock) => await this.saveCertStr(value) : async () => {}; const onFeatureChange = isMainInstance - ? async (features: TFeatures) => await this.onFeatureChange(features) + ? async () => await this.onFeatureChange() + : async () => {}; + const onLicenseRenewed = isMainInstance + ? async () => await this.onLicenseRenewed() : async () => {}; const collectUsageMetrics = isMainInstance ? async () => await this.licenseMetricsService.collectUsageMetrics() @@ -102,6 +105,7 @@ export class License implements LicenseProvider { collectUsageMetrics, collectPassthroughData, onFeatureChange, + onLicenseRenewed, }); await this.manager.initialize(); @@ -129,24 +133,16 @@ export class License implements LicenseProvider { return databaseSettings?.value ?? ''; } - async onFeatureChange(_features: TFeatures): Promise { - const { isMultiMain, isLeader } = this.instanceSettings; + private async onFeatureChange() { + void this.broadcastReloadLicenseCommand(); + } - if (Object.keys(_features).length === 0) { - this.logger.error('Empty license features recieved', { isMultiMain, isLeader }); - return; - } + private async onLicenseRenewed() { + void this.broadcastReloadLicenseCommand(); + } - this.logger.debug('License feature change detected', _features); - - if (isMultiMain && !isLeader) { - this.logger - .scoped(['scaling', 'multi-main-setup', 'license']) - .debug('Instance is not leader, skipping sending of "reload-license" command...'); - return; - } - - if (config.getEnv('executions.mode') === 'queue') { + private async broadcastReloadLicenseCommand() { + if (config.getEnv('executions.mode') === 'queue' && this.instanceSettings.isLeader) { const { Publisher } = await import('@/scaling/pubsub/publisher.service'); await Container.get(Publisher).publishCommand({ command: 'reload-license' }); }