refactor(core): Move instanceType to InstanceSettings (no-changelog) (#10640)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-09-16 13:37:14 +02:00
committed by GitHub
parent 50beefb658
commit 25c8a328a8
25 changed files with 85 additions and 89 deletions

View File

@@ -5,7 +5,6 @@ import { InstanceSettings } from 'n8n-core';
import { ApplicationError } from 'n8n-workflow';
import Container from 'typedi';
import config from '@/config';
import type { OrchestrationService } from '@/services/orchestration.service';
import { mockInstance } from '@test/mocking';
@@ -70,7 +69,8 @@ describe('ScalingService', () => {
beforeEach(() => {
jest.clearAllMocks();
config.set('generic.instanceType', 'main');
// @ts-expect-error readonly property
instanceSettings.instanceType = 'main';
instanceSettings.markAsLeader();
scalingService = new ScalingService(
@@ -128,8 +128,8 @@ describe('ScalingService', () => {
describe('if worker', () => {
it('should set up queue + listeners', async () => {
// @ts-expect-error Private field
scalingService.instanceType = 'worker';
// @ts-expect-error readonly property
instanceSettings.instanceType = 'worker';
await scalingService.setupQueue();
@@ -141,8 +141,8 @@ describe('ScalingService', () => {
describe('webhook', () => {
it('should set up a queue + listeners', async () => {
// @ts-expect-error Private field
scalingService.instanceType = 'webhook';
// @ts-expect-error readonly property
instanceSettings.instanceType = 'webhook';
await scalingService.setupQueue();
@@ -155,8 +155,8 @@ describe('ScalingService', () => {
describe('setupWorker', () => {
it('should set up a worker with concurrency', async () => {
// @ts-expect-error Private field
scalingService.instanceType = 'worker';
// @ts-expect-error readonly property
instanceSettings.instanceType = 'worker';
await scalingService.setupQueue();
const concurrency = 5;
@@ -172,8 +172,8 @@ describe('ScalingService', () => {
});
it('should throw if called before queue is ready', async () => {
// @ts-expect-error Private field
scalingService.instanceType = 'worker';
// @ts-expect-error readonly property
instanceSettings.instanceType = 'worker';
expect(() => scalingService.setupWorker(5)).toThrow();
});

View File

@@ -31,8 +31,6 @@ import type {
export class ScalingService {
private queue: JobQueue;
private readonly instanceType = config.getEnv('generic.instanceType');
constructor(
private readonly logger: Logger,
private readonly activeExecutions: ActiveExecutions,
@@ -211,9 +209,10 @@ export class ScalingService {
throw error;
});
if (this.instanceType === 'main' || this.instanceType === 'webhook') {
const { instanceType } = this.instanceSettings;
if (instanceType === 'main' || instanceType === 'webhook') {
this.registerMainOrWebhookListeners();
} else if (this.instanceType === 'worker') {
} else if (instanceType === 'worker') {
this.registerWorkerListeners();
}
}
@@ -295,7 +294,7 @@ export class ScalingService {
}
private assertWorker() {
if (this.instanceType === 'worker') return;
if (this.instanceSettings.instanceType === 'worker') return;
throw new ApplicationError('This method must be called on a `worker` instance');
}
@@ -311,7 +310,7 @@ export class ScalingService {
get isQueueMetricsEnabled() {
return (
this.globalConfig.endpoints.metrics.includeQueueMetrics &&
this.instanceType === 'main' &&
this.instanceSettings.instanceType === 'main' &&
!this.orchestrationService.isMultiMainSetupEnabled
);
}