mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Move multi-main state to InstanceSettings (#12144)
This commit is contained in:
@@ -5,7 +5,6 @@ import { InstanceSettings } from 'n8n-core';
|
||||
import { ApplicationError } from 'n8n-workflow';
|
||||
import Container from 'typedi';
|
||||
|
||||
import type { OrchestrationService } from '@/services/orchestration.service';
|
||||
import { mockInstance, mockLogger } from '@test/mocking';
|
||||
|
||||
import { JOB_TYPE_NAME, QUEUE_NAME } from '../constants';
|
||||
@@ -47,7 +46,6 @@ describe('ScalingService', () => {
|
||||
});
|
||||
|
||||
const instanceSettings = Container.get(InstanceSettings);
|
||||
const orchestrationService = mock<OrchestrationService>({ isMultiMainSetupEnabled: false });
|
||||
const jobProcessor = mock<JobProcessor>();
|
||||
|
||||
let scalingService: ScalingService;
|
||||
@@ -82,7 +80,7 @@ describe('ScalingService', () => {
|
||||
globalConfig,
|
||||
mock(),
|
||||
instanceSettings,
|
||||
orchestrationService,
|
||||
mock(),
|
||||
mock(),
|
||||
);
|
||||
|
||||
|
||||
@@ -66,9 +66,11 @@ export class ScalingService {
|
||||
|
||||
this.registerListeners();
|
||||
|
||||
if (this.instanceSettings.isLeader) this.scheduleQueueRecovery();
|
||||
const { isLeader, isMultiMain } = this.instanceSettings;
|
||||
|
||||
if (this.orchestrationService.isMultiMainSetupEnabled) {
|
||||
if (isLeader) this.scheduleQueueRecovery();
|
||||
|
||||
if (isMultiMain) {
|
||||
this.orchestrationService.multiMainSetup
|
||||
.on('leader-takeover', () => this.scheduleQueueRecovery())
|
||||
.on('leader-stepdown', () => this.stopQueueRecovery());
|
||||
@@ -127,7 +129,7 @@ export class ScalingService {
|
||||
}
|
||||
|
||||
private async stopMain() {
|
||||
if (this.orchestrationService.isSingleMainSetup) {
|
||||
if (this.instanceSettings.isSingleMain) {
|
||||
await this.queue.pause(true, true); // no more jobs will be picked up
|
||||
this.logger.debug('Queue paused');
|
||||
}
|
||||
@@ -373,7 +375,7 @@ export class ScalingService {
|
||||
return (
|
||||
this.globalConfig.endpoints.metrics.includeQueueMetrics &&
|
||||
this.instanceSettings.instanceType === 'main' &&
|
||||
!this.orchestrationService.isMultiMainSetupEnabled
|
||||
this.instanceSettings.isSingleMain
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user