mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Simplify OrchestrationService (no-changelog) (#8364)
This commit is contained in:
@@ -17,7 +17,7 @@ import type { User } from '@db/entities/User';
|
||||
import type { WebhookEntity } from '@db/entities/WebhookEntity';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
import { chooseRandomly } from './shared/random';
|
||||
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
import { setSchedulerAsLoadedNode } from './shared/utils';
|
||||
import * as testDb from './shared/testDb';
|
||||
@@ -34,8 +34,8 @@ mockInstance(ExecutionService);
|
||||
mockInstance(WorkflowService);
|
||||
|
||||
const webhookService = mockInstance(WebhookService);
|
||||
const multiMainSetup = mockInstance(MultiMainSetup, {
|
||||
isEnabled: false,
|
||||
const orchestrationService = mockInstance(OrchestrationService, {
|
||||
isMultiMainSetupEnabled: false,
|
||||
isLeader: false,
|
||||
isFollower: false,
|
||||
});
|
||||
@@ -266,8 +266,8 @@ describe('add()', () => {
|
||||
|
||||
const workflow = await createWorkflow({ active: true }, owner);
|
||||
|
||||
jest.replaceProperty(multiMainSetup, 'isEnabled', true);
|
||||
jest.replaceProperty(multiMainSetup, 'isLeader', true);
|
||||
jest.replaceProperty(orchestrationService, 'isMultiMainSetupEnabled', true);
|
||||
jest.replaceProperty(orchestrationService, 'isLeader', true);
|
||||
|
||||
const addWebhooksSpy = jest.spyOn(activeWorkflowRunner, 'addWebhooks');
|
||||
const addTriggersAndPollersSpy = jest.spyOn(
|
||||
@@ -290,8 +290,8 @@ describe('add()', () => {
|
||||
test('should add triggers and pollers only', async () => {
|
||||
const mode = 'leadershipChange';
|
||||
|
||||
jest.replaceProperty(multiMainSetup, 'isEnabled', true);
|
||||
jest.replaceProperty(multiMainSetup, 'isLeader', true);
|
||||
jest.replaceProperty(orchestrationService, 'isMultiMainSetupEnabled', true);
|
||||
jest.replaceProperty(orchestrationService, 'isLeader', true);
|
||||
|
||||
const workflow = await createWorkflow({ active: true }, owner);
|
||||
|
||||
@@ -318,8 +318,8 @@ describe('add()', () => {
|
||||
test('should not add webhooks, triggers or pollers', async () => {
|
||||
const mode = chooseRandomly(NON_LEADERSHIP_CHANGE_MODES);
|
||||
|
||||
jest.replaceProperty(multiMainSetup, 'isEnabled', true);
|
||||
jest.replaceProperty(multiMainSetup, 'isLeader', false);
|
||||
jest.replaceProperty(orchestrationService, 'isMultiMainSetupEnabled', true);
|
||||
jest.replaceProperty(orchestrationService, 'isLeader', false);
|
||||
|
||||
const workflow = await createWorkflow({ active: true }, owner);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { PostHogClient } from '@/posthog';
|
||||
import { RedisService } from '@/services/redis.service';
|
||||
import { OrchestrationHandlerWorkerService } from '@/services/orchestration/worker/orchestration.handler.worker.service';
|
||||
import { OrchestrationWorkerService } from '@/services/orchestration/worker/orchestration.worker.service';
|
||||
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
|
||||
@@ -38,7 +38,7 @@ beforeAll(async () => {
|
||||
mockInstance(RedisService);
|
||||
mockInstance(RedisServicePubSubPublisher);
|
||||
mockInstance(RedisServicePubSubSubscriber);
|
||||
mockInstance(MultiMainSetup);
|
||||
mockInstance(OrchestrationService);
|
||||
});
|
||||
|
||||
test('worker initializes all its components', async () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { WorkflowEntity } from '@/databases/entities/WorkflowEntity';
|
||||
import { setupTestServer } from './shared/utils';
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import { createOwner } from './shared/db/users';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
||||
|
||||
describe('DebugController', () => {
|
||||
@@ -36,9 +37,9 @@ describe('DebugController', () => {
|
||||
activeWorkflowRunner.allActiveInMemory.mockReturnValue([workflowId]);
|
||||
activeWorkflowRunner.getAllWorkflowActivationErrors.mockResolvedValue(activationErrors);
|
||||
|
||||
jest.spyOn(MultiMainSetup.prototype, 'instanceId', 'get').mockReturnValue(instanceId);
|
||||
jest.spyOn(OrchestrationService.prototype, 'instanceId', 'get').mockReturnValue(instanceId);
|
||||
jest.spyOn(MultiMainSetup.prototype, 'fetchLeaderKey').mockResolvedValue(leaderKey);
|
||||
jest.spyOn(MultiMainSetup.prototype, 'isLeader', 'get').mockReturnValue(true);
|
||||
jest.spyOn(OrchestrationService.prototype, 'isLeader', 'get').mockReturnValue(true);
|
||||
|
||||
const response = await ownerAgent.get('/debug/multi-main-setup').expect(200);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { AUTH_COOKIE_NAME } from '@/constants';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { SettingsRepository } from '@db/repositories/settings.repository';
|
||||
import { mockNodeTypesData } from '../../../unit/Helpers';
|
||||
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import { mockInstance } from '../../../shared/mocking';
|
||||
import { ExecutionService } from '@/executions/execution.service';
|
||||
|
||||
@@ -30,7 +30,7 @@ export { setupTestServer } from './testServer';
|
||||
* Initialize node types.
|
||||
*/
|
||||
export async function initActiveWorkflowRunner() {
|
||||
mockInstance(MultiMainSetup);
|
||||
mockInstance(OrchestrationService);
|
||||
|
||||
mockInstance(ExecutionService);
|
||||
const { ActiveWorkflowRunner } = await import('@/ActiveWorkflowRunner');
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||
import { Telemetry } from '@/telemetry';
|
||||
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import { WorkflowService } from '@/workflows/workflow.service';
|
||||
|
||||
import * as testDb from '../shared/testDb';
|
||||
@@ -14,13 +14,13 @@ import { createWorkflow } from '../shared/db/workflows';
|
||||
|
||||
let workflowService: WorkflowService;
|
||||
let activeWorkflowRunner: ActiveWorkflowRunner;
|
||||
let multiMainSetup: MultiMainSetup;
|
||||
let orchestrationService: OrchestrationService;
|
||||
|
||||
beforeAll(async () => {
|
||||
await testDb.init();
|
||||
|
||||
activeWorkflowRunner = mockInstance(ActiveWorkflowRunner);
|
||||
multiMainSetup = mockInstance(MultiMainSetup);
|
||||
orchestrationService = mockInstance(OrchestrationService);
|
||||
mockInstance(Telemetry);
|
||||
|
||||
workflowService = new WorkflowService(
|
||||
@@ -33,7 +33,7 @@ beforeAll(async () => {
|
||||
mock(),
|
||||
mock(),
|
||||
mock(),
|
||||
multiMainSetup,
|
||||
orchestrationService,
|
||||
mock(),
|
||||
activeWorkflowRunner,
|
||||
);
|
||||
@@ -89,7 +89,7 @@ describe('update()', () => {
|
||||
const owner = await createOwner();
|
||||
const workflow = await createWorkflow({ active: true }, owner);
|
||||
|
||||
const publishSpy = jest.spyOn(multiMainSetup, 'publish');
|
||||
const publishSpy = jest.spyOn(orchestrationService, 'publish');
|
||||
|
||||
workflow.active = false;
|
||||
await workflowService.update(owner, workflow, workflow.id);
|
||||
@@ -109,7 +109,7 @@ describe('update()', () => {
|
||||
const owner = await createOwner();
|
||||
const workflow = await createWorkflow({ active: true }, owner);
|
||||
|
||||
const publishSpy = jest.spyOn(multiMainSetup, 'publish');
|
||||
const publishSpy = jest.spyOn(orchestrationService, 'publish');
|
||||
|
||||
await workflowService.update(owner, workflow, workflow.id);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { License } from '@/License';
|
||||
import { Logger } from '@/Logger';
|
||||
import { N8N_VERSION } from '@/constants';
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
|
||||
jest.mock('@n8n_io/license-sdk');
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('License', () => {
|
||||
let license: License;
|
||||
const logger = mockInstance(Logger);
|
||||
const instanceSettings = mockInstance(InstanceSettings, { instanceId: MOCK_INSTANCE_ID });
|
||||
mockInstance(MultiMainSetup);
|
||||
mockInstance(OrchestrationService);
|
||||
|
||||
beforeEach(async () => {
|
||||
license = new License(logger, instanceSettings, mock(), mock(), mock());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Container from 'typedi';
|
||||
import config from '@/config';
|
||||
import { SingleMainSetup } from '@/services/orchestration/main/SingleMainSetup';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import type { RedisServiceWorkerResponseObject } from '@/services/redis/RedisServiceCommands';
|
||||
import { eventBus } from '@/eventbus';
|
||||
import { RedisService } from '@/services/redis.service';
|
||||
@@ -14,7 +14,7 @@ import { Push } from '@/push';
|
||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
|
||||
const os = Container.get(SingleMainSetup);
|
||||
const os = Container.get(OrchestrationService);
|
||||
const handler = Container.get(OrchestrationHandlerMainService);
|
||||
mockInstance(ActiveWorkflowRunner);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user