mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
fix(core): Add safeguard for command publishing (#11337)
This commit is contained in:
parent
f4ea943c9c
commit
656439e871
|
@ -44,6 +44,16 @@ describe('Publisher', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('publishCommand', () => {
|
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<PubSub.Command>({ command: 'reload-license' });
|
||||||
|
|
||||||
|
await publisher.publishCommand(msg);
|
||||||
|
|
||||||
|
expect(client.publish).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should publish command into `n8n.commands` pubsub channel', async () => {
|
it('should publish command into `n8n.commands` pubsub channel', async () => {
|
||||||
const publisher = new Publisher(logger, redisClientService, instanceSettings);
|
const publisher = new Publisher(logger, redisClientService, instanceSettings);
|
||||||
const msg = mock<PubSub.Command>({ command: 'reload-license' });
|
const msg = mock<PubSub.Command>({ command: 'reload-license' });
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class Publisher {
|
||||||
private readonly redisClientService: RedisClientService,
|
private readonly redisClientService: RedisClientService,
|
||||||
private readonly instanceSettings: InstanceSettings,
|
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;
|
if (config.getEnv('executions.mode') !== 'queue') return;
|
||||||
|
|
||||||
this.logger = this.logger.scoped(['scaling', 'pubsub']);
|
this.logger = this.logger.scoped(['scaling', 'pubsub']);
|
||||||
|
@ -46,6 +46,9 @@ export class Publisher {
|
||||||
|
|
||||||
/** Publish a command into the `n8n.commands` channel. */
|
/** Publish a command into the `n8n.commands` channel. */
|
||||||
async publishCommand(msg: Omit<PubSub.Command, 'senderId'>) {
|
async publishCommand(msg: Omit<PubSub.Command, 'senderId'>) {
|
||||||
|
// @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(
|
await this.client.publish(
|
||||||
'n8n.commands',
|
'n8n.commands',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|
Loading…
Reference in a new issue