refactor: Delete dead crash recovery code (no-changelog) (#9512)

This commit is contained in:
Iván Ovejero 2024-05-27 13:55:52 +02:00 committed by GitHub
parent 49b5bd70f0
commit 008f62aaf4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 3 additions and 93 deletions

View file

@ -66,11 +66,3 @@ export type EventMessageTypes =
| EventMessageAudit
| EventMessageNode
| EventMessageAiNode;
export interface FailedEventSummary {
lastNodeExecuted: string;
executionId: string;
name: string;
event: string;
timestamp: string;
}

View file

@ -13,11 +13,7 @@ import { WorkflowRepository } from '@db/repositories/workflow.repository';
import { OrchestrationService } from '@/services/orchestration.service';
import { Logger } from '@/Logger';
import type {
EventMessageTypes,
EventNamesTypes,
FailedEventSummary,
} from '../EventMessageClasses/';
import type { EventMessageTypes } from '../EventMessageClasses/';
import type { MessageEventBusDestination } from '../MessageEventBusDestination/MessageEventBusDestination.ee';
import { MessageEventBusLogWriter } from '../MessageEventBusWriter/MessageEventBusLogWriter';
import { messageEventBusDestinationFromDb } from '../MessageEventBusDestination/MessageEventBusDestinationFromDb';
@ -361,48 +357,6 @@ export class MessageEventBus extends EventEmitter {
);
}
async getEventsFailed(amount = 5): Promise<FailedEventSummary[]> {
const result: FailedEventSummary[] = [];
try {
const queryResult = await this.logWriter?.getMessagesAll();
const uniques = uniqby(queryResult, 'id');
const filteredExecutionIds = uniques
.filter((e) =>
(['n8n.workflow.crashed', 'n8n.workflow.failed'] as EventNamesTypes[]).includes(
e.eventName,
),
)
.map((e) => ({
executionId: e.payload.executionId as string,
name: e.payload.workflowName,
timestamp: e.ts,
event: e.eventName,
}))
.filter((e) => e)
.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
.slice(-amount);
for (const execution of filteredExecutionIds) {
const data = await this.recoveryService.recoverExecutionData(
execution.executionId,
queryResult,
false,
);
if (data) {
const lastNodeExecuted = data.resultData.lastNodeExecuted;
result.push({
lastNodeExecuted: lastNodeExecuted ?? '',
executionId: execution.executionId,
name: execution.name as string,
event: execution.event,
timestamp: execution.timestamp.toISO(),
});
}
}
} catch {}
return result;
}
async getEventsAll(): Promise<EventMessageTypes[]> {
const queryResult = await this.logWriter?.getMessagesAll();
const filtered = uniqby(queryResult, 'id');

View file

@ -1,5 +1,4 @@
import express from 'express';
import type { IRunExecutionData } from 'n8n-workflow';
import { EventMessageTypeNames } from 'n8n-workflow';
import { RestController, Get, Post, GlobalScope } from '@/decorators';
@ -11,13 +10,12 @@ import type { EventMessageWorkflowOptions } from './EventMessageClasses/EventMes
import { EventMessageWorkflow } from './EventMessageClasses/EventMessageWorkflow';
import type { EventMessageReturnMode } from './MessageEventBus/MessageEventBus';
import { MessageEventBus } from './MessageEventBus/MessageEventBus';
import type { EventMessageTypes, FailedEventSummary } from './EventMessageClasses';
import type { EventMessageTypes } from './EventMessageClasses';
import { eventNamesAll } from './EventMessageClasses';
import type { EventMessageAuditOptions } from './EventMessageClasses/EventMessageAudit';
import { EventMessageAudit } from './EventMessageClasses/EventMessageAudit';
import type { EventMessageNodeOptions } from './EventMessageClasses/EventMessageNode';
import { EventMessageNode } from './EventMessageClasses/EventMessageNode';
import { ExecutionDataRecoveryService } from './executionDataRecovery.service';
// ----------------------------------------
// TypeGuards
@ -35,10 +33,7 @@ const isWithQueryString = (candidate: unknown): candidate is { query: string } =
@RestController('/eventbus')
export class EventBusController {
constructor(
private readonly eventBus: MessageEventBus,
private readonly recoveryService: ExecutionDataRecoveryService,
) {}
constructor(private readonly eventBus: MessageEventBus) {}
// ----------------------------------------
// Events
@ -65,13 +60,6 @@ export class EventBusController {
}
}
@Get('/failed')
@GlobalScope('eventBusEvent:list')
async getFailedEvents(req: express.Request): Promise<FailedEventSummary[]> {
const amount = parseInt(req.query?.amount as string) ?? 5;
return await this.eventBus.getEventsFailed(amount);
}
@Get('/execution/:id')
@GlobalScope('eventBusEvent:read')
async getEventForExecutionId(req: express.Request): Promise<EventMessageTypes[] | undefined> {
@ -85,21 +73,6 @@ export class EventBusController {
return;
}
@Get('/execution-recover/:id')
@GlobalScope('eventBusEvent:read')
async getRecoveryForExecutionId(req: express.Request): Promise<IRunExecutionData | undefined> {
const { id } = req.params;
if (req.params?.id) {
const logHistory = parseInt(req.query.logHistory as string, 10) || undefined;
const applyToDb = req.query.applyToDb !== undefined ? !!req.query.applyToDb : true;
const messages = await this.eventBus.getEventsByExecutionId(id, logHistory);
if (messages.length > 0) {
return await this.recoveryService.recoverExecutionData(id, messages, applyToDb);
}
}
return;
}
@Post('/event')
@GlobalScope('eventBusEvent:create')
async postEvent(req: express.Request): Promise<EventMessageTypes | undefined> {

View file

@ -17,7 +17,6 @@ export const GLOBAL_OWNER_SCOPES: Scope[] = [
'eventBusEvent:read',
'eventBusEvent:update',
'eventBusEvent:delete',
'eventBusEvent:list',
'eventBusEvent:query',
'eventBusEvent:create',
'eventBusDestination:create',
@ -80,7 +79,6 @@ export const GLOBAL_OWNER_SCOPES: Scope[] = [
export const GLOBAL_ADMIN_SCOPES = GLOBAL_OWNER_SCOPES.concat();
export const GLOBAL_MEMBER_SCOPES: Scope[] = [
'eventBusEvent:list',
'eventBusEvent:read',
'eventBusDestination:list',
'eventBusDestination:test',

View file

@ -45,10 +45,3 @@ export async function getDestinationsFromBackend(
export async function getExecutionEvents(context: IRestApiContext, executionId: string) {
return await makeRestApiRequest(context, 'GET', `/eventbus/execution/${executionId}`);
}
export async function recoverExecutionDataFromEvents(
context: IRestApiContext,
executionId: string,
) {
return await makeRestApiRequest(context, 'GET', `/eventbus/execution-recover/${executionId}`);
}