feat: Enable Task Runners on Scaling mode Workers (no-changelog) (#11253)

This commit is contained in:
Val 2024-10-15 11:03:28 +01:00 committed by GitHub
parent ee6e7fec85
commit ecbe568d69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 3 deletions

View file

@ -21,7 +21,7 @@ import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus'
import { EventService } from '@/events/event.service'; import { EventService } from '@/events/event.service';
import { ExecutionService } from '@/executions/execution.service'; import { ExecutionService } from '@/executions/execution.service';
import { License } from '@/license'; import { License } from '@/license';
import { SingleMainTaskManager } from '@/runners/task-managers/single-main-task-manager'; import { LocalTaskManager } from '@/runners/task-managers/local-task-manager';
import { TaskManager } from '@/runners/task-managers/task-manager'; import { TaskManager } from '@/runners/task-managers/task-manager';
import { PubSubHandler } from '@/scaling/pubsub/pubsub-handler'; import { PubSubHandler } from '@/scaling/pubsub/pubsub-handler';
import { Subscriber } from '@/scaling/pubsub/subscriber.service'; import { Subscriber } from '@/scaling/pubsub/subscriber.service';
@ -227,7 +227,7 @@ export class Start extends BaseCommand {
} }
if (!this.globalConfig.taskRunners.disabled) { if (!this.globalConfig.taskRunners.disabled) {
Container.set(TaskManager, new SingleMainTaskManager()); Container.set(TaskManager, new LocalTaskManager());
const { TaskRunnerServer } = await import('@/runners/task-runner-server'); const { TaskRunnerServer } = await import('@/runners/task-runner-server');
const taskRunnerServer = Container.get(TaskRunnerServer); const taskRunnerServer = Container.get(TaskRunnerServer);
await taskRunnerServer.start(); await taskRunnerServer.start();

View file

@ -8,6 +8,8 @@ import { EventMessageGeneric } from '@/eventbus/event-message-classes/event-mess
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus'; import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { LogStreamingEventRelay } from '@/events/relays/log-streaming.event-relay'; import { LogStreamingEventRelay } from '@/events/relays/log-streaming.event-relay';
import { Logger } from '@/logging/logger.service'; import { Logger } from '@/logging/logger.service';
import { LocalTaskManager } from '@/runners/task-managers/local-task-manager';
import { TaskManager } from '@/runners/task-managers/task-manager';
import { PubSubHandler } from '@/scaling/pubsub/pubsub-handler'; import { PubSubHandler } from '@/scaling/pubsub/pubsub-handler';
import { Subscriber } from '@/scaling/pubsub/subscriber.service'; import { Subscriber } from '@/scaling/pubsub/subscriber.service';
import type { ScalingService } from '@/scaling/scaling.service'; import type { ScalingService } from '@/scaling/scaling.service';
@ -113,6 +115,17 @@ export class Worker extends BaseCommand {
}, },
}), }),
); );
if (!this.globalConfig.taskRunners.disabled) {
Container.set(TaskManager, new LocalTaskManager());
const { TaskRunnerServer } = await import('@/runners/task-runner-server');
const taskRunnerServer = Container.get(TaskRunnerServer);
await taskRunnerServer.start();
const { TaskRunnerProcess } = await import('@/runners/task-runner-process');
const runnerProcess = Container.get(TaskRunnerProcess);
await runnerProcess.start();
}
} }
async initEventBus() { async initEventBus() {

View file

@ -5,7 +5,7 @@ import type { RequesterMessage } from '../runner-types';
import type { RequesterMessageCallback } from '../task-broker.service'; import type { RequesterMessageCallback } from '../task-broker.service';
import { TaskBroker } from '../task-broker.service'; import { TaskBroker } from '../task-broker.service';
export class SingleMainTaskManager extends TaskManager { export class LocalTaskManager extends TaskManager {
taskBroker: TaskBroker; taskBroker: TaskBroker;
id: string = 'single-main'; id: string = 'single-main';

View file

@ -1,6 +1,8 @@
process.argv[2] = 'worker'; process.argv[2] = 'worker';
import { TaskRunnersConfig } from '@n8n/config';
import { BinaryDataService } from 'n8n-core'; import { BinaryDataService } from 'n8n-core';
import Container from 'typedi';
import { Worker } from '@/commands/worker'; import { Worker } from '@/commands/worker';
import config from '@/config'; import config from '@/config';
@ -11,6 +13,8 @@ import { ExternalSecretsManager } from '@/external-secrets/external-secrets-mana
import { License } from '@/license'; import { License } from '@/license';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials'; import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { Push } from '@/push'; import { Push } from '@/push';
import { TaskRunnerProcess } from '@/runners/task-runner-process';
import { TaskRunnerServer } from '@/runners/task-runner-server';
import { Publisher } from '@/scaling/pubsub/publisher.service'; import { Publisher } from '@/scaling/pubsub/publisher.service';
import { Subscriber } from '@/scaling/pubsub/subscriber.service'; import { Subscriber } from '@/scaling/pubsub/subscriber.service';
import { ScalingService } from '@/scaling/scaling.service'; import { ScalingService } from '@/scaling/scaling.service';
@ -22,6 +26,7 @@ import { mockInstance } from '../../shared/mocking';
config.set('executions.mode', 'queue'); config.set('executions.mode', 'queue');
config.set('binaryDataManager.availableModes', 'filesystem'); config.set('binaryDataManager.availableModes', 'filesystem');
Container.get(TaskRunnersConfig).disabled = false;
mockInstance(LoadNodesAndCredentials); mockInstance(LoadNodesAndCredentials);
const binaryDataService = mockInstance(BinaryDataService); const binaryDataService = mockInstance(BinaryDataService);
const externalHooks = mockInstance(ExternalHooks); const externalHooks = mockInstance(ExternalHooks);
@ -31,6 +36,8 @@ const messageEventBus = mockInstance(MessageEventBus);
const logStreamingEventRelay = mockInstance(LogStreamingEventRelay); const logStreamingEventRelay = mockInstance(LogStreamingEventRelay);
const scalingService = mockInstance(ScalingService); const scalingService = mockInstance(ScalingService);
const orchestrationWorkerService = mockInstance(OrchestrationWorkerService); const orchestrationWorkerService = mockInstance(OrchestrationWorkerService);
const taskRunnerServer = mockInstance(TaskRunnerServer);
const taskRunnerProcess = mockInstance(TaskRunnerProcess);
mockInstance(Publisher); mockInstance(Publisher);
mockInstance(Subscriber); mockInstance(Subscriber);
mockInstance(Telemetry); mockInstance(Telemetry);
@ -55,6 +62,8 @@ test('worker initializes all its components', async () => {
expect(logStreamingEventRelay.init).toHaveBeenCalledTimes(1); expect(logStreamingEventRelay.init).toHaveBeenCalledTimes(1);
expect(orchestrationWorkerService.init).toHaveBeenCalledTimes(1); expect(orchestrationWorkerService.init).toHaveBeenCalledTimes(1);
expect(messageEventBus.send).toHaveBeenCalledTimes(1); expect(messageEventBus.send).toHaveBeenCalledTimes(1);
expect(taskRunnerServer.start).toHaveBeenCalledTimes(1);
expect(taskRunnerProcess.start).toHaveBeenCalledTimes(1);
expect(config.getEnv('executions.mode')).toBe('queue'); expect(config.getEnv('executions.mode')).toBe('queue');
}); });