Skip to content

Commit 5b3db5d

Browse files
authored
chore(core): Check for instance type in offloading warning (#15960)
1 parent 2178cfe commit 5b3db5d

File tree

2 files changed

+79
-46
lines changed

2 files changed

+79
-46
lines changed

packages/cli/src/deprecation/__tests__/deprecation.service.test.ts

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Logger } from '@n8n/backend-common';
22
import { GlobalConfig } from '@n8n/config';
33
import { captor, mock } from 'jest-mock-extended';
4+
import { InstanceSettings } from 'n8n-core';
5+
import type { InstanceType } from 'n8n-core';
46

57
import config from '@/config';
68
import { mockInstance } from '@test/mocking';
@@ -10,7 +12,8 @@ import { DeprecationService } from '../deprecation.service';
1012
describe('DeprecationService', () => {
1113
const logger = mock<Logger>();
1214
const globalConfig = mockInstance(GlobalConfig, { nodes: { exclude: [] } });
13-
const deprecationService = new DeprecationService(logger, globalConfig);
15+
const instanceSettings = mockInstance(InstanceSettings, { instanceType: 'main' });
16+
const deprecationService = new DeprecationService(logger, globalConfig, instanceSettings);
1417

1518
beforeEach(() => {
1619
// Ignore environment variables coming in from the environment when running
@@ -122,7 +125,7 @@ describe('DeprecationService', () => {
122125
},
123126
});
124127

125-
new DeprecationService(logger, globalConfig).warn();
128+
new DeprecationService(logger, globalConfig, instanceSettings).warn();
126129

127130
expect(logger.warn).not.toHaveBeenCalled();
128131
});
@@ -140,62 +143,89 @@ describe('DeprecationService', () => {
140143
});
141144
});
142145

143-
describe('when executions.mode is queue', () => {
144-
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is false', () => {
145-
process.env[envVar] = 'false';
146-
147-
const service = new DeprecationService(logger, globalConfig);
148-
service.warn();
146+
describe('when executions.mode is not queue', () => {
147+
test.each([['main'], ['worker'], ['webhook']])(
148+
'should not warn for instanceType %s',
149+
(instanceType: InstanceType) => {
150+
jest.spyOn(config, 'getEnv').mockImplementation((key) => {
151+
if (key === 'executions.mode') return 'regular';
152+
return;
153+
});
154+
process.env[envVar] = 'false';
155+
const service = new DeprecationService(
156+
logger,
157+
globalConfig,
158+
mock<InstanceSettings>({ instanceType }),
159+
);
160+
service.warn();
161+
expect(logger.warn).not.toHaveBeenCalled();
162+
},
163+
);
164+
});
149165

150-
expect(logger.warn).toHaveBeenCalledTimes(1);
151-
const warningMessage = logger.warn.mock.calls[0][0];
152-
expect(warningMessage).toContain(envVar);
166+
describe('when executions.mode is queue', () => {
167+
describe('when instanceType is worker', () => {
168+
test.each([
169+
['false', 'false'],
170+
['empty string', ''],
171+
])(`should not warn when ${envVar} is %s`, (_description, envValue) => {
172+
process.env[envVar] = envValue;
173+
const service = new DeprecationService(
174+
logger,
175+
globalConfig,
176+
mock<InstanceSettings>({ instanceType: 'worker' }),
177+
);
178+
service.warn();
179+
expect(logger.warn).not.toHaveBeenCalled();
180+
});
153181
});
154182

155-
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is empty', () => {
156-
process.env[envVar] = '';
157-
158-
const service = new DeprecationService(logger, globalConfig);
159-
service.warn();
160-
161-
expect(logger.warn).toHaveBeenCalledTimes(1);
162-
const warningMessage = logger.warn.mock.calls[0][0];
163-
expect(warningMessage).toContain(envVar);
183+
describe('when instanceType is webhook', () => {
184+
test.each([
185+
['false', 'false'],
186+
['empty string', ''],
187+
])(`should not warn when ${envVar} is %s`, (_description, envValue) => {
188+
process.env[envVar] = envValue;
189+
const service = new DeprecationService(
190+
logger,
191+
globalConfig,
192+
mock<InstanceSettings>({ instanceType: 'webhook' }),
193+
);
194+
service.warn();
195+
expect(logger.warn).not.toHaveBeenCalled();
196+
});
164197
});
165198

166-
test('should not warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is true', () => {
167-
process.env[envVar] = 'true';
199+
describe('when instanceType is main', () => {
200+
test.each([
201+
['false', 'false'],
202+
['empty string', ''],
203+
])(`should warn when ${envVar} is %s`, (_description, envValue) => {
204+
process.env[envVar] = envValue;
205+
const service = new DeprecationService(logger, globalConfig, instanceSettings);
206+
service.warn();
207+
expect(logger.warn).toHaveBeenCalled();
208+
});
168209

169-
const service = new DeprecationService(logger, globalConfig);
170-
service.warn();
210+
test('should not warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is true', () => {
211+
process.env[envVar] = 'true';
171212

172-
expect(logger.warn).not.toHaveBeenCalled();
173-
});
213+
const service = new DeprecationService(logger, globalConfig, instanceSettings);
214+
service.warn();
174215

175-
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is undefined', () => {
176-
delete process.env[envVar];
216+
expect(logger.warn).not.toHaveBeenCalled();
217+
});
177218

178-
const service = new DeprecationService(logger, globalConfig);
179-
service.warn();
219+
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is undefined', () => {
220+
delete process.env[envVar];
180221

181-
expect(logger.warn).toHaveBeenCalledTimes(1);
182-
const warningMessage = logger.warn.mock.calls[0][0];
183-
expect(warningMessage).toContain(envVar);
184-
});
185-
});
222+
const service = new DeprecationService(logger, globalConfig, instanceSettings);
223+
service.warn();
186224

187-
describe('when executions.mode is not queue', () => {
188-
test('should not warn', () => {
189-
jest.spyOn(config, 'getEnv').mockImplementation((key) => {
190-
if (key === 'executions.mode') return 'regular';
191-
return;
225+
expect(logger.warn).toHaveBeenCalledTimes(1);
226+
const warningMessage = logger.warn.mock.calls[0][0];
227+
expect(warningMessage).toContain(envVar);
192228
});
193-
process.env[envVar] = 'false';
194-
195-
const service = new DeprecationService(logger, globalConfig);
196-
service.warn();
197-
198-
expect(logger.warn).not.toHaveBeenCalled();
199229
});
200230
});
201231
});

packages/cli/src/deprecation/deprecation.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Logger } from '@n8n/backend-common';
22
import { GlobalConfig } from '@n8n/config';
33
import { Service } from '@n8n/di';
4+
import { InstanceSettings } from 'n8n-core';
45

56
import config from '@/config';
67

@@ -65,6 +66,7 @@ export class DeprecationService {
6566
checkValue: (value?: string) => value?.toLowerCase() !== 'true' && value !== '1',
6667
warnIfMissing: true,
6768
matchConfig: config.getEnv('executions.mode') === 'queue',
69+
disableIf: () => this.instanceSettings.instanceType !== 'main',
6870
},
6971
{
7072
envVar: 'N8N_PARTIAL_EXECUTION_VERSION_DEFAULT',
@@ -103,6 +105,7 @@ export class DeprecationService {
103105
constructor(
104106
private readonly logger: Logger,
105107
private readonly globalConfig: GlobalConfig,
108+
private readonly instanceSettings: InstanceSettings,
106109
) {}
107110

108111
warn() {

0 commit comments

Comments
 (0)