refactor(core): Bring active executions into executions controller (no-changelog) (#8371)
This commit is contained in:
@@ -23,7 +23,7 @@ import { parse, stringify } from 'flatted';
|
||||
import {
|
||||
ApplicationError,
|
||||
type ExecutionStatus,
|
||||
type IExecutionsSummary,
|
||||
type ExecutionSummary,
|
||||
type IRunExecutionData,
|
||||
} from 'n8n-workflow';
|
||||
import { BinaryDataService } from 'n8n-core';
|
||||
@@ -41,6 +41,7 @@ import { ExecutionEntity } from '../entities/ExecutionEntity';
|
||||
import { ExecutionMetadata } from '../entities/ExecutionMetadata';
|
||||
import { ExecutionDataRepository } from './executionData.repository';
|
||||
import { Logger } from '@/Logger';
|
||||
import type { GetManyActiveFilter } from '@/executions/execution.types';
|
||||
|
||||
function parseFiltersToQueryBuilder(
|
||||
qb: SelectQueryBuilder<ExecutionEntity>,
|
||||
@@ -343,7 +344,7 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
excludedExecutionIds: string[],
|
||||
accessibleWorkflowIds: string[],
|
||||
additionalFilters?: { lastId?: string; firstId?: string },
|
||||
): Promise<IExecutionsSummary[]> {
|
||||
): Promise<ExecutionSummary[]> {
|
||||
if (accessibleWorkflowIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@@ -657,6 +658,47 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||
unflattenData: false,
|
||||
});
|
||||
}
|
||||
|
||||
async findIfAccessible(executionId: string, accessibleWorkflowIds: string[]) {
|
||||
return await this.findSingleExecution(executionId, {
|
||||
where: { workflowId: In(accessibleWorkflowIds) },
|
||||
});
|
||||
}
|
||||
|
||||
async getManyActive(
|
||||
activeExecutionIds: string[],
|
||||
accessibleWorkflowIds: string[],
|
||||
filter?: GetManyActiveFilter,
|
||||
) {
|
||||
const where: FindOptionsWhere<ExecutionEntity> = {
|
||||
id: In(activeExecutionIds),
|
||||
status: Not(In(['finished', 'stopped', 'failed', 'crashed'] as ExecutionStatus[])),
|
||||
};
|
||||
|
||||
if (filter) {
|
||||
const { workflowId, status, finished } = filter;
|
||||
if (workflowId && accessibleWorkflowIds.includes(workflowId)) {
|
||||
where.workflowId = workflowId;
|
||||
} else {
|
||||
where.workflowId = In(accessibleWorkflowIds);
|
||||
}
|
||||
if (status) {
|
||||
// @ts-ignore
|
||||
where.status = In(status);
|
||||
}
|
||||
if (finished !== undefined) {
|
||||
where.finished = finished;
|
||||
}
|
||||
} else {
|
||||
where.workflowId = In(accessibleWorkflowIds);
|
||||
}
|
||||
|
||||
return await this.findMultipleExecutions({
|
||||
select: ['id', 'workflowId', 'mode', 'retryOf', 'startedAt', 'stoppedAt', 'status'],
|
||||
order: { id: 'DESC' },
|
||||
where,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface IGetExecutionsQueryFilter {
|
||||
|
||||
Reference in New Issue
Block a user