Skip to content

Commit

Permalink
fix(core): Account for retry of execution aborted by pre-execute hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed May 21, 2024
1 parent 5ef45e8 commit d72cf46
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/cli/src/errors/aborted-execution-retry.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApplicationError } from 'n8n-workflow';

export class AbortedExecutionRetryError extends ApplicationError {
constructor() {
super('The execution was aborted before starting, so it cannot be retried', {
level: 'warning',
});
}
}
3 changes: 3 additions & 0 deletions packages/cli/src/executions/execution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { NotFoundError } from '@/errors/response-errors/not-found.error';
import config from '@/config';
import { WaitTracker } from '@/WaitTracker';
import type { ExecutionEntity } from '@/databases/entities/ExecutionEntity';
import { AbortedExecutionRetryError } from '@/errors/aborted-execution-retry.error';

export const schemaGetExecutionsQueryFilter = {
$id: '/IGetExecutionsQueryFilter',
Expand Down Expand Up @@ -129,6 +130,8 @@ export class ExecutionService {
throw new NotFoundError(`The execution with the ID "${executionId}" does not exist.`);
}

if (!execution.data.executionData) throw new AbortedExecutionRetryError();

if (execution.finished) {
throw new ApplicationError('The execution succeeded, so it cannot be retried.');
}
Expand Down
30 changes: 30 additions & 0 deletions packages/cli/test/unit/services/execution.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { IExecutionResponse } from '@/Interfaces';
import type { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { AbortedExecutionRetryError } from '@/errors/aborted-execution-retry.error';
import { ExecutionService } from '@/executions/execution.service';
import type { ExecutionRequest } from '@/executions/execution.types';
import { mock } from 'jest-mock-extended';

describe('ExecutionService', () => {
const executionRepository = mock<ExecutionRepository>();
const executionService = new ExecutionService(
mock(),
mock(),
mock(),
executionRepository,
mock(),
mock(),
mock(),
mock(),
);

it('should error on retrying an aborted execution', async () => {
const abortedExecutionData = mock<IExecutionResponse>({ data: { executionData: undefined } });
executionRepository.findWithUnflattenedData.mockResolvedValue(abortedExecutionData);
const req = mock<ExecutionRequest.Retry>();

const retry = executionService.retry(req, []);

await expect(retry).rejects.toThrow(AbortedExecutionRetryError);
});
});
2 changes: 1 addition & 1 deletion packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@
"nodeView.runButtonText.executeWorkflow": "Test workflow",
"nodeView.runButtonText.executingWorkflow": "Executing workflow",
"nodeView.runButtonText.waitingForTriggerEvent": "Waiting for trigger event",
"nodeView.showError.workflowError": "Workflow execution finished with an error",
"nodeView.showError.workflowError": "Workflow execution had an error",
"nodeView.showError.getWorkflowDataFromUrl.title": "Problem loading workflow",
"nodeView.showError.importWorkflowData.title": "Problem importing workflow",
"nodeView.showError.mounted1.message": "There was a problem loading init data",
Expand Down

0 comments on commit d72cf46

Please sign in to comment.