refactor(core): Simplify OrchestrationService (no-changelog) (#8364)

This commit is contained in:
Iván Ovejero
2024-01-22 11:16:29 +01:00
committed by GitHub
parent 2ccb754e52
commit f35d4fcbd8
28 changed files with 323 additions and 315 deletions

View File

@@ -3,7 +3,7 @@ import { assert, jsonStringify } from 'n8n-workflow';
import type { IPushDataType } from '@/Interfaces';
import type { Logger } from '@/Logger';
import type { User } from '@db/entities/User';
import type { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
import type { OrchestrationService } from '@/services/orchestration.service';
/**
* Abstract class for two-way push communication.
@@ -21,7 +21,7 @@ export abstract class AbstractPush<T> extends EventEmitter {
constructor(
protected readonly logger: Logger,
private readonly multiMainSetup: MultiMainSetup,
private readonly orchestrationService: OrchestrationService,
) {
super();
}
@@ -84,10 +84,10 @@ export abstract class AbstractPush<T> extends EventEmitter {
* the webhook. If so, the handler process commands the creator process to
* relay the former's execution lifecyle events to the creator's frontend.
*/
if (this.multiMainSetup.isEnabled && !this.hasSessionId(sessionId)) {
if (this.orchestrationService.isMultiMainSetupEnabled && !this.hasSessionId(sessionId)) {
const payload = { type, args: data, sessionId };
void this.multiMainSetup.publish('relay-execution-lifecycle-event', payload);
void this.orchestrationService.publish('relay-execution-lifecycle-event', payload);
return;
}

View File

@@ -4,7 +4,7 @@ import { Logger } from '@/Logger';
import { AbstractPush } from './abstract.push';
import type { PushRequest, PushResponse } from './types';
import type { User } from '@db/entities/User';
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
import { OrchestrationService } from '@/services/orchestration.service';
type Connection = { req: PushRequest; res: PushResponse };
@@ -14,8 +14,8 @@ export class SSEPush extends AbstractPush<Connection> {
readonly connections: Record<string, Connection> = {};
constructor(logger: Logger, multiMainSetup: MultiMainSetup) {
super(logger, multiMainSetup);
constructor(logger: Logger, orchestrationService: OrchestrationService) {
super(logger, orchestrationService);
this.channel.on('disconnect', (channel, { req }) => {
this.remove(req?.query?.sessionId);

View File

@@ -3,7 +3,7 @@ import { Service } from 'typedi';
import { Logger } from '@/Logger';
import { AbstractPush } from './abstract.push';
import type { User } from '@db/entities/User';
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
import { OrchestrationService } from '@/services/orchestration.service';
function heartbeat(this: WebSocket) {
this.isAlive = true;
@@ -11,8 +11,8 @@ function heartbeat(this: WebSocket) {
@Service()
export class WebSocketPush extends AbstractPush<WebSocket> {
constructor(logger: Logger, multiMainSetup: MultiMainSetup) {
super(logger, multiMainSetup);
constructor(logger: Logger, orchestrationService: OrchestrationService) {
super(logger, orchestrationService);
// Ping all connected clients every 60 seconds
setInterval(() => this.pingAll(), 60 * 1000);