From 656439e87138f9f96dea5a683cfdac3f661ffefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 24 Oct 2024 13:22:28 +0200 Subject: [PATCH] fix(core): Add safeguard for command publishing (#11337) --- .../src/scaling/__tests__/publisher.service.test.ts | 10 ++++++++++ packages/cli/src/scaling/pubsub/publisher.service.ts | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/scaling/__tests__/publisher.service.test.ts b/packages/cli/src/scaling/__tests__/publisher.service.test.ts index f77b6b5d5afbe..f69ad08cb5995 100644 --- a/packages/cli/src/scaling/__tests__/publisher.service.test.ts +++ b/packages/cli/src/scaling/__tests__/publisher.service.test.ts @@ -44,6 +44,16 @@ describe('Publisher', () => { }); describe('publishCommand', () => { + it('should do nothing if not in scaling mode', async () => { + config.set('executions.mode', 'regular'); + const publisher = new Publisher(logger, redisClientService, instanceSettings); + const msg = mock({ command: 'reload-license' }); + + await publisher.publishCommand(msg); + + expect(client.publish).not.toHaveBeenCalled(); + }); + it('should publish command into `n8n.commands` pubsub channel', async () => { const publisher = new Publisher(logger, redisClientService, instanceSettings); const msg = mock({ command: 'reload-license' }); diff --git a/packages/cli/src/scaling/pubsub/publisher.service.ts b/packages/cli/src/scaling/pubsub/publisher.service.ts index cc28c2d339d81..248a455e3ef55 100644 --- a/packages/cli/src/scaling/pubsub/publisher.service.ts +++ b/packages/cli/src/scaling/pubsub/publisher.service.ts @@ -23,7 +23,7 @@ export class Publisher { private readonly redisClientService: RedisClientService, private readonly instanceSettings: InstanceSettings, ) { - // @TODO: Once this class is only ever initialized in scaling mode, throw in the next line instead. + // @TODO: Once this class is only ever initialized in scaling mode, assert in the next line. if (config.getEnv('executions.mode') !== 'queue') return; this.logger = this.logger.scoped(['scaling', 'pubsub']); @@ -46,6 +46,9 @@ export class Publisher { /** Publish a command into the `n8n.commands` channel. */ async publishCommand(msg: Omit) { + // @TODO: Once this class is only ever used in scaling mode, remove next line. + if (config.getEnv('executions.mode') !== 'queue') return; + await this.client.publish( 'n8n.commands', JSON.stringify({