mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
chore(core): Check for instance type in offloading warning (#15960)
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import type { Logger } from '@n8n/backend-common';
|
import type { Logger } from '@n8n/backend-common';
|
||||||
import { GlobalConfig } from '@n8n/config';
|
import { GlobalConfig } from '@n8n/config';
|
||||||
import { captor, mock } from 'jest-mock-extended';
|
import { captor, mock } from 'jest-mock-extended';
|
||||||
|
import { InstanceSettings } from 'n8n-core';
|
||||||
|
import type { InstanceType } from 'n8n-core';
|
||||||
|
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import { mockInstance } from '@test/mocking';
|
import { mockInstance } from '@test/mocking';
|
||||||
@@ -10,7 +12,8 @@ import { DeprecationService } from '../deprecation.service';
|
|||||||
describe('DeprecationService', () => {
|
describe('DeprecationService', () => {
|
||||||
const logger = mock<Logger>();
|
const logger = mock<Logger>();
|
||||||
const globalConfig = mockInstance(GlobalConfig, { nodes: { exclude: [] } });
|
const globalConfig = mockInstance(GlobalConfig, { nodes: { exclude: [] } });
|
||||||
const deprecationService = new DeprecationService(logger, globalConfig);
|
const instanceSettings = mockInstance(InstanceSettings, { instanceType: 'main' });
|
||||||
|
const deprecationService = new DeprecationService(logger, globalConfig, instanceSettings);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Ignore environment variables coming in from the environment when running
|
// Ignore environment variables coming in from the environment when running
|
||||||
@@ -122,7 +125,7 @@ describe('DeprecationService', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
new DeprecationService(logger, globalConfig).warn();
|
new DeprecationService(logger, globalConfig, instanceSettings).warn();
|
||||||
|
|
||||||
expect(logger.warn).not.toHaveBeenCalled();
|
expect(logger.warn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -140,62 +143,89 @@ describe('DeprecationService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when executions.mode is queue', () => {
|
describe('when executions.mode is not queue', () => {
|
||||||
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is false', () => {
|
test.each([['main'], ['worker'], ['webhook']])(
|
||||||
process.env[envVar] = 'false';
|
'should not warn for instanceType %s',
|
||||||
|
(instanceType: InstanceType) => {
|
||||||
const service = new DeprecationService(logger, globalConfig);
|
jest.spyOn(config, 'getEnv').mockImplementation((key) => {
|
||||||
service.warn();
|
if (key === 'executions.mode') return 'regular';
|
||||||
|
return;
|
||||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
});
|
||||||
const warningMessage = logger.warn.mock.calls[0][0];
|
process.env[envVar] = 'false';
|
||||||
expect(warningMessage).toContain(envVar);
|
const service = new DeprecationService(
|
||||||
});
|
logger,
|
||||||
|
globalConfig,
|
||||||
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is empty', () => {
|
mock<InstanceSettings>({ instanceType }),
|
||||||
process.env[envVar] = '';
|
);
|
||||||
|
service.warn();
|
||||||
const service = new DeprecationService(logger, globalConfig);
|
expect(logger.warn).not.toHaveBeenCalled();
|
||||||
service.warn();
|
},
|
||||||
|
);
|
||||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
|
||||||
const warningMessage = logger.warn.mock.calls[0][0];
|
|
||||||
expect(warningMessage).toContain(envVar);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should not warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is true', () => {
|
|
||||||
process.env[envVar] = 'true';
|
|
||||||
|
|
||||||
const service = new DeprecationService(logger, globalConfig);
|
|
||||||
service.warn();
|
|
||||||
|
|
||||||
expect(logger.warn).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is undefined', () => {
|
|
||||||
delete process.env[envVar];
|
|
||||||
|
|
||||||
const service = new DeprecationService(logger, globalConfig);
|
|
||||||
service.warn();
|
|
||||||
|
|
||||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
|
||||||
const warningMessage = logger.warn.mock.calls[0][0];
|
|
||||||
expect(warningMessage).toContain(envVar);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when executions.mode is not queue', () => {
|
describe('when executions.mode is queue', () => {
|
||||||
test('should not warn', () => {
|
describe('when instanceType is worker', () => {
|
||||||
jest.spyOn(config, 'getEnv').mockImplementation((key) => {
|
test.each([
|
||||||
if (key === 'executions.mode') return 'regular';
|
['false', 'false'],
|
||||||
return;
|
['empty string', ''],
|
||||||
|
])(`should not warn when ${envVar} is %s`, (_description, envValue) => {
|
||||||
|
process.env[envVar] = envValue;
|
||||||
|
const service = new DeprecationService(
|
||||||
|
logger,
|
||||||
|
globalConfig,
|
||||||
|
mock<InstanceSettings>({ instanceType: 'worker' }),
|
||||||
|
);
|
||||||
|
service.warn();
|
||||||
|
expect(logger.warn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
process.env[envVar] = 'false';
|
});
|
||||||
|
|
||||||
const service = new DeprecationService(logger, globalConfig);
|
describe('when instanceType is webhook', () => {
|
||||||
service.warn();
|
test.each([
|
||||||
|
['false', 'false'],
|
||||||
|
['empty string', ''],
|
||||||
|
])(`should not warn when ${envVar} is %s`, (_description, envValue) => {
|
||||||
|
process.env[envVar] = envValue;
|
||||||
|
const service = new DeprecationService(
|
||||||
|
logger,
|
||||||
|
globalConfig,
|
||||||
|
mock<InstanceSettings>({ instanceType: 'webhook' }),
|
||||||
|
);
|
||||||
|
service.warn();
|
||||||
|
expect(logger.warn).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
expect(logger.warn).not.toHaveBeenCalled();
|
describe('when instanceType is main', () => {
|
||||||
|
test.each([
|
||||||
|
['false', 'false'],
|
||||||
|
['empty string', ''],
|
||||||
|
])(`should warn when ${envVar} is %s`, (_description, envValue) => {
|
||||||
|
process.env[envVar] = envValue;
|
||||||
|
const service = new DeprecationService(logger, globalConfig, instanceSettings);
|
||||||
|
service.warn();
|
||||||
|
expect(logger.warn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is true', () => {
|
||||||
|
process.env[envVar] = 'true';
|
||||||
|
|
||||||
|
const service = new DeprecationService(logger, globalConfig, instanceSettings);
|
||||||
|
service.warn();
|
||||||
|
|
||||||
|
expect(logger.warn).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should warn when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is undefined', () => {
|
||||||
|
delete process.env[envVar];
|
||||||
|
|
||||||
|
const service = new DeprecationService(logger, globalConfig, instanceSettings);
|
||||||
|
service.warn();
|
||||||
|
|
||||||
|
expect(logger.warn).toHaveBeenCalledTimes(1);
|
||||||
|
const warningMessage = logger.warn.mock.calls[0][0];
|
||||||
|
expect(warningMessage).toContain(envVar);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Logger } from '@n8n/backend-common';
|
import { Logger } from '@n8n/backend-common';
|
||||||
import { GlobalConfig } from '@n8n/config';
|
import { GlobalConfig } from '@n8n/config';
|
||||||
import { Service } from '@n8n/di';
|
import { Service } from '@n8n/di';
|
||||||
|
import { InstanceSettings } from 'n8n-core';
|
||||||
|
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ export class DeprecationService {
|
|||||||
checkValue: (value?: string) => value?.toLowerCase() !== 'true' && value !== '1',
|
checkValue: (value?: string) => value?.toLowerCase() !== 'true' && value !== '1',
|
||||||
warnIfMissing: true,
|
warnIfMissing: true,
|
||||||
matchConfig: config.getEnv('executions.mode') === 'queue',
|
matchConfig: config.getEnv('executions.mode') === 'queue',
|
||||||
|
disableIf: () => this.instanceSettings.instanceType !== 'main',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
envVar: 'N8N_PARTIAL_EXECUTION_VERSION_DEFAULT',
|
envVar: 'N8N_PARTIAL_EXECUTION_VERSION_DEFAULT',
|
||||||
@@ -103,6 +105,7 @@ export class DeprecationService {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly logger: Logger,
|
private readonly logger: Logger,
|
||||||
private readonly globalConfig: GlobalConfig,
|
private readonly globalConfig: GlobalConfig,
|
||||||
|
private readonly instanceSettings: InstanceSettings,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
|
|||||||
Reference in New Issue
Block a user