Skip to content

Commit

Permalink
refactor: Report from execution repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Jul 2, 2024
1 parent 274cff9 commit e6ac65c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
12 changes: 2 additions & 10 deletions packages/cli/src/ActiveExecutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,11 @@ export class ActiveExecutions {
let executionStatus: ExecutionStatus = executionId ? 'running' : 'new';
const mode = executionData.executionMode;

const runExecutionData = executionData.executionData;

if (!runExecutionData) {
throw new ApplicationError('Cannot add active execution without execution data', {
extra: { workflowId: executionData.workflowData.id },
});
}

if (executionId === undefined) {
// Is a new execution so save in DB

const fullExecutionData: ExecutionPayload = {
data: runExecutionData,
data: executionData.executionData!,
mode,
finished: false,
startedAt: new Date(),
Expand Down Expand Up @@ -91,7 +83,7 @@ export class ActiveExecutions {

const execution: Pick<IExecutionDb, 'id' | 'data' | 'waitTill' | 'status'> = {
id: executionId,
data: runExecutionData,
data: executionData.executionData!,
waitTill: null,
status: executionStatus,
};
Expand Down
20 changes: 18 additions & 2 deletions packages/cli/src/databases/repositories/execution.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { ExecutionDataRepository } from './executionData.repository';
import { Logger } from '@/Logger';
import type { ExecutionSummaries } from '@/executions/execution.types';
import { PostgresLiveRowsRetrievalError } from '@/errors/postgres-live-rows-retrieval.error';
import { separate } from '@/utils';
import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';

export interface IGetExecutionsQueryFilter {
id?: FindOperator<string> | string;
Expand Down Expand Up @@ -156,7 +158,9 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
const executions = await this.find(queryParams);

if (options?.includeData && options?.unflattenData) {
return executions.map((execution) => {
const [valid, invalid] = separate(executions, (e) => e.executionData !== null);
this.reportInvalidExecutions(invalid);
return valid.map((execution) => {
const { executionData, metadata, ...rest } = execution;
return {
...rest,
Expand All @@ -166,7 +170,9 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
} as IExecutionResponse;
});
} else if (options?.includeData) {
return executions.map((execution) => {
const [valid, invalid] = separate(executions, (e) => e.executionData !== null);
this.reportInvalidExecutions(invalid);
return valid.map((execution) => {
const { executionData, metadata, ...rest } = execution;
return {
...rest,
Expand All @@ -183,6 +189,16 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
});
}

reportInvalidExecutions(executions: ExecutionEntity[]) {
if (executions.length === 0) return;

ErrorReporter.error(
new ApplicationError('Found executions without executionData', {
extra: { executionIds: executions.map(({ id }) => id) },
}),
);
}

async findSingleExecution(
id: string,
options?: {
Expand Down
1 change: 0 additions & 1 deletion packages/cli/test/unit/ActiveExecutions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function mockExecutionData(): IWorkflowExecutionDataProcess {
nodes: [],
connections: {},
},
executionData: { resultData: { runData: {} } },
userId: uuid(),
};
}
Expand Down

0 comments on commit e6ac65c

Please sign in to comment.