Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Organize all event maps #10997

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { generateHostInstanceId } from '@/databases/utils/generators';
import * as Db from '@/db';
import { initErrorHandling } from '@/error-reporting';
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { TelemetryEventRelay } from '@/events/telemetry-event-relay';
import { TelemetryEventRelay } from '@/events/relays/telemetry.event-relay';
import { initExpressionEvaluator } from '@/expression-evaluator';
import { ExternalHooks } from '@/external-hooks';
import { ExternalSecretsManager } from '@/external-secrets/external-secrets-manager.ee';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import config from '@/config';
import { N8N_VERSION, inTest } from '@/constants';
import { EventMessageGeneric } from '@/eventbus/event-message-classes/event-message-generic';
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { LogStreamingEventRelay } from '@/events/log-streaming-event-relay';
import { LogStreamingEventRelay } from '@/events/relays/log-streaming.event-relay';
import { JobProcessor } from '@/scaling/job-processor';
import { Publisher } from '@/scaling/pubsub/publisher.service';
import type { ScalingService } from '@/scaling/scaling.service';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/decorators/redactable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RedactableError } from '@/errors/redactable.error';
import type { UserLike } from '@/events/relay-event-map';
import type { UserLike } from '@/events/maps/relay.event-map';

function toRedactable(userLike: UserLike) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { INode, IRun, IWorkflowBase } from 'n8n-workflow';

import type { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { EventService } from '@/events/event.service';
import { LogStreamingEventRelay } from '@/events/log-streaming-event-relay';
import type { RelayEventMap } from '@/events/relay-event-map';
import type { RelayEventMap } from '@/events/maps/relay.event-map';
import { LogStreamingEventRelay } from '@/events/relays/log-streaming.event-relay';
import type { IWorkflowDb } from '@/interfaces';

describe('LogStreamingEventRelay', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type { ProjectRelationRepository } from '@/databases/repositories/project
import type { SharedWorkflowRepository } from '@/databases/repositories/shared-workflow.repository';
import type { WorkflowRepository } from '@/databases/repositories/workflow.repository';
import { EventService } from '@/events/event.service';
import type { RelayEventMap } from '@/events/relay-event-map';
import { TelemetryEventRelay } from '@/events/telemetry-event-relay';
import type { RelayEventMap } from '@/events/maps/relay.event-map';
import { TelemetryEventRelay } from '@/events/relays/telemetry.event-relay';
import type { IWorkflowDb } from '@/interfaces';
import type { License } from '@/license';
import type { NodeTypes } from '@/node-types';
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/events/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { Service } from 'typedi';

import { TypedEmitter } from '@/typed-emitter';

import type { AiEventMap } from './ai-event-map';
import type { QueueMetricsEventMap } from './queue-metrics-event-map';
import type { RelayEventMap } from './relay-event-map';
import type { AiEventMap } from './maps/ai.event-map';
import type { PubSubEventMap } from './maps/pub-sub.event-map';
import type { QueueMetricsEventMap } from './maps/queue-metrics.event-map';
import type { RelayEventMap } from './maps/relay.event-map';

type EventMap = RelayEventMap & QueueMetricsEventMap & AiEventMap;
type EventMap = RelayEventMap & QueueMetricsEventMap & AiEventMap & PubSubEventMap;

@Service()
export class EventService extends TypedEmitter<EventMap> {}
104 changes: 104 additions & 0 deletions packages/cli/src/events/maps/pub-sub.event-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import type { WorkerStatus, PushType } from '@n8n/api-types';

import type { IWorkflowDb } from '@/interfaces';

export type PubSubEventMap = PubSubCommandMap & PubSubWorkerResponseMap;

export type PubSubCommandMap = {
// #region Lifecycle

'reload-license': never;

'restart-event-bus': never;

'reload-external-secrets-providers': never;

// #endregion

// #region Community packages

'community-package-install': {
packageName: string;
packageVersion: string;
};

'community-package-update': {
packageName: string;
packageVersion: string;
};

'community-package-uninstall': {
packageName: string;
};

// #endregion

// #region Worker view

'get-worker-id': never;

'get-worker-status': never;

// #endregion

// #region Multi-main setup

'add-webhooks-triggers-and-pollers': {
workflowId: string;
};

'remove-triggers-and-pollers': {
workflowId: string;
};

'display-workflow-activation': {
workflowId: string;
};

'display-workflow-deactivation': {
workflowId: string;
};

'display-workflow-activation-error': {
workflowId: string;
errorMessage: string;
};

'relay-execution-lifecycle-event': {
type: PushType;
args: Record<string, unknown>;
pushRef: string;
};

'clear-test-webhooks': {
webhookKey: string;
workflowEntity: IWorkflowDb;
pushRef: string;
};

// #endregion
};

export type PubSubWorkerResponseMap = {
// #region Lifecycle

'restart-event-bus': {
result: 'success' | 'error';
error?: string;
};

'reload-external-secrets-providers': {
result: 'success' | 'error';
error?: string;
};

// #endregion

// #region Worker view

'get-worker-id': never;

'get-worker-status': WorkerStatus;

// #endregion
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ProjectRole } from '@/databases/entities/project-relation';
import type { GlobalRole } from '@/databases/entities/user';
import type { IWorkflowDb } from '@/interfaces';

import type { AiEventMap } from './ai-event-map';
import type { AiEventMap } from './ai.event-map';

export type UserLike = {
id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Service } from 'typedi';

import type { RelayEventMap } from '@/events/relay-event-map';

import { EventService } from './event.service';
import { EventService } from '@/events/event.service';
import type { RelayEventMap } from '@/events/maps/relay.event-map';

@Service()
export class EventRelay {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { Service } from 'typedi';

import { Redactable } from '@/decorators/redactable';
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { EventRelay } from '@/events/event-relay';
import type { RelayEventMap } from '@/events/relay-event-map';

import { EventService } from './event.service';
import { EventService } from '@/events/event.service';
import type { RelayEventMap } from '@/events/maps/relay.event-map';
import { EventRelay } from '@/events/relays/event-relay';

@Service()
export class LogStreamingEventRelay extends EventRelay {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { ProjectRelationRepository } from '@/databases/repositories/project-rela
import { SharedWorkflowRepository } from '@/databases/repositories/shared-workflow.repository';
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
import { EventService } from '@/events/event.service';
import type { RelayEventMap } from '@/events/relay-event-map';
import type { RelayEventMap } from '@/events/maps/relay.event-map';
import { determineFinalExecutionStatus } from '@/execution-lifecycle-hooks/shared/shared-hook-functions';
import type { IExecutionTrackProperties } from '@/interfaces';
import { License } from '@/license';
import { NodeTypes } from '@/node-types';

import { EventRelay } from './event-relay';
import { Telemetry } from '../telemetry';
import { Telemetry } from '../../telemetry';

@Service()
export class TelemetryEventRelay extends EventRelay {
Expand Down
Loading
Loading