import { Logger } from '@n8n/backend-common'; import { GlobalConfig } from '@n8n/config'; import type { FindManyOptions, FindOperator, FindOptionsWhere } from '@n8n/typeorm'; import { DataSource } from '@n8n/typeorm'; import { BinaryDataService, ErrorReporter } from 'n8n-core'; import type { ExecutionStatus, ExecutionSummary, IWorkflowSettings, WorkflowExecuteMode } from 'n8n-workflow'; import { ExecutionDataStorageLocation, ExecutionEntity } from '../entities'; import type { ActivityProjectScope } from './activity-event.repository'; import { BaseRepository } from './base-repository'; import { SharedWorkflowRepository } from './shared-workflow.repository'; import type { ExecutionSummaries, IExecutionBase, IExecutionFlattedDb, IExecutionResponse } from '../entities/types-db'; import { TransactionRunner } from '../services/transaction'; export type CrashedExecution = { id: string; workflowId: string; workflowName?: string; mode: WorkflowExecuteMode; startedAt: Date | null; stoppedAt: Date; tracingContext?: { traceparent: string; tracestate?: string; identity?: Record; }; workflowVersionId?: string; retryOf?: string; workflowCustomTelemetryTags?: IWorkflowSettings['customTelemetryTags']; project?: { id: string; customTelemetryTags: Array<{ key: string; value: string; }>; }; }; export interface UpdateExecutionConditions { requireStatus?: ExecutionStatus; requireNotFinished?: boolean; requireNotCanceled?: boolean; } export interface IGetExecutionsQueryFilter { id?: FindOperator | string; finished?: boolean; mode?: string; retryOf?: string; retrySuccessId?: string; status?: ExecutionStatus[]; workflowId?: string; waitTill?: FindOperator | boolean; metadata?: Array<{ key: string; value: string; exactMatch?: boolean; }>; startedAfter?: string; startedBefore?: string; } export type ExecutionDeletionCriteria = { filters: IGetExecutionsQueryFilter | undefined; accessibleWorkflowIds: string[]; deleteConditions: { deleteBefore?: Date; ids?: string[]; }; }; export declare class ExecutionRepository extends BaseRepository { private readonly globalConfig; private readonly logger; private readonly errorReporter; private readonly binaryDataService; private readonly sharedWorkflowRepository; readonly hardDeletionBatchSize = 100; constructor(dataSource: DataSource, globalConfig: GlobalConfig, logger: Logger, errorReporter: ErrorReporter, binaryDataService: BinaryDataService, sharedWorkflowRepository: SharedWorkflowRepository, transactionRunner: TransactionRunner); findMultipleExecutions(queryParams: FindManyOptions, options?: { unflattenData: true; includeData?: true; }): Promise; findMultipleExecutions(queryParams: FindManyOptions, options?: { unflattenData?: false | undefined; includeData?: true; }): Promise; findMultipleExecutions(queryParams: FindManyOptions, options?: { unflattenData?: boolean; includeData?: boolean; }): Promise; reportInvalidExecutions(executions: ExecutionEntity[]): void; private serializeAnnotation; existsForAccessibleWorkflows(executionId: string, accessibleWorkflowIds: string[]): Promise; findSingleExecution(id: string, options?: { includeData: true; includeAnnotation?: boolean; unflattenData: true; where?: FindOptionsWhere; }): Promise; findSingleExecution(id: string, options?: { includeData: true; includeAnnotation?: boolean; unflattenData?: false | undefined; where?: FindOptionsWhere; }): Promise; findSingleExecution(id: string, options?: { includeData?: boolean; includeAnnotation?: boolean; unflattenData?: boolean; where?: FindOptionsWhere; }): Promise; markAsCrashed(executionIds: string | string[], onBatchTransitioned?: (batch: CrashedExecution[]) => void): Promise; markWorkflowExecutionsAsCrashed(workflowId: string): Promise; private transitionToCrashed; private withOwnerProjects; setRunning(executionId: string): Promise; updateExistingExecution(executionId: string, execution: Partial, conditions?: UpdateExecutionConditions): Promise; deleteExecutionsByFilter({ filters, accessibleWorkflowIds, deleteConditions, }: ExecutionDeletionCriteria): Promise>; getIdsSince(date: Date): Promise; softDeletePrunableExecutions(): Promise; findSoftDeletedExecutions(before?: string): Promise<{ workflowId: string; executionId: string; storedAt: ExecutionDataStorageLocation; }[]>; deleteByIds(executionIds: string[]): Promise; getWaitingExecutions(): Promise; findParkedOnSubExecution(): Promise; countInWorkflows(workflowIds: string[], options: { limit: number; lastId?: string; status?: ExecutionStatus; excludedExecutionsIds?: string[]; startedAfter?: string; startedBefore?: string; }): Promise; summariseRunsForProjects(query: { projectIds: ActivityProjectScope; stoppedAfter: Date; stoppedBefore: Date; workflowLimit: number; mcpVisibleOnly?: boolean; }): Promise>; private getStatusCondition; private getIdCondition; getFindManyInWorkflowsCondition(workflowIds: string[], options?: { lastId?: string; status?: ExecutionStatus; excludedExecutionsIds?: string[]; startedAfter?: string; startedBefore?: string; }): FindOptionsWhere; findIfShared(executionId: string, sharedWorkflowIds: string[]): Promise; findIfAccessible(executionId: string, accessibleWorkflowIds: string[]): Promise; stopBeforeRun(execution: IExecutionResponse): Promise; cancelMany(executionIds: string[]): Promise; cancelManyRunning(executionIds: string[]): Promise; private summaryFields; private annotationFields; private reduceExecutionsWithAnnotations; findManyByRangeQuery(query: ExecutionSummaries.RangeQuery): Promise; private toSummary; fetchCount(query: ExecutionSummaries.CountQuery): Promise; getLiveExecutionRowsOnPostgres(): Promise; private toQueryBuilder; private toQueryBuilderWithAnnotations; getWorkflowIdsWithExecutionsSince(date: Date): Promise; getDistinctVersionIds(workflowId: string): Promise; findUnfinishedIds(): Promise; findStatusesByIds(ids: string[]): Promise>>; getAllIds(): Promise; getInProgressExecutionIds(batchSize: number): Promise; getConcurrentExecutionsCount(): Promise; private handleExecutionRunData; findByStopExecutionsFilter(query: ExecutionSummaries.StopExecutionFilterQuery): Promise>; }