fix(core): Fix execution status filters (#5533)
* fix status filters * fix countfilter * add migrations to backfill status * fix migrations
This commit is contained in:
committed by
GitHub
parent
52f740b9e8
commit
17eff4d7d6
18
packages/cli/src/executions/executionHelpers.ts
Normal file
18
packages/cli/src/executions/executionHelpers.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { IExecutionFlattedDb } from '../Interfaces';
|
||||
import type { ExecutionStatus } from 'n8n-workflow';
|
||||
|
||||
export function getStatusUsingPreviousExecutionStatusMethod(
|
||||
execution: IExecutionFlattedDb,
|
||||
): ExecutionStatus {
|
||||
if (execution.waitTill) {
|
||||
return 'waiting';
|
||||
} else if (execution.stoppedAt === undefined) {
|
||||
return 'running';
|
||||
} else if (execution.finished) {
|
||||
return 'success';
|
||||
} else if (execution.stoppedAt !== null) {
|
||||
return 'failed';
|
||||
} else {
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import * as Db from '@/Db';
|
||||
import * as GenericHelpers from '@/GenericHelpers';
|
||||
import { parse } from 'flatted';
|
||||
import { Container } from 'typedi';
|
||||
import { getStatusUsingPreviousExecutionStatusMethod } from './executionHelpers';
|
||||
|
||||
interface IGetExecutionsQueryFilter {
|
||||
id?: FindOperator<string>;
|
||||
@@ -213,7 +214,6 @@ export class ExecutionsService {
|
||||
};
|
||||
if (filter?.status) {
|
||||
Object.assign(findWhere, { status: In(filter.status) });
|
||||
delete filter.status; // remove status from filter so it does not get applied twice
|
||||
}
|
||||
if (filter?.finished) {
|
||||
Object.assign(findWhere, { finished: filter.finished });
|
||||
@@ -259,12 +259,18 @@ export class ExecutionsService {
|
||||
'execution.startedAt',
|
||||
'execution.stoppedAt',
|
||||
'execution.workflowData',
|
||||
'execution.status',
|
||||
])
|
||||
.orderBy('id', 'DESC')
|
||||
.take(limit)
|
||||
.where(findWhere);
|
||||
|
||||
const countFilter = deepCopy(filter ?? {});
|
||||
// deepcopy breaks the In operator so we need to reapply it
|
||||
if (filter?.status) {
|
||||
Object.assign(filter, { status: In(filter.status) });
|
||||
Object.assign(countFilter, { status: In(filter.status) });
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
this.massageFilters(filter as IDataObject);
|
||||
@@ -286,6 +292,10 @@ export class ExecutionsService {
|
||||
const nodeExecutionStatus = {};
|
||||
let lastNodeExecuted;
|
||||
let executionError;
|
||||
// fill execution status for old executions that will return null
|
||||
if (!execution.status) {
|
||||
execution.status = getStatusUsingPreviousExecutionStatusMethod(execution);
|
||||
}
|
||||
try {
|
||||
const data = parse(execution.data) as IRunExecutionData;
|
||||
lastNodeExecuted = data?.resultData?.lastNodeExecuted ?? '';
|
||||
@@ -363,6 +373,10 @@ export class ExecutionsService {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!execution.status) {
|
||||
execution.status = getStatusUsingPreviousExecutionStatusMethod(execution);
|
||||
}
|
||||
|
||||
if (req.query.unflattedResponse === 'true') {
|
||||
return ResponseHelper.unflattenExecutionData(execution);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user