Skip to content

Commit

Permalink
fix(core): Fix execution cancellation issues in scaling mode (#12343)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Dec 30, 2024
1 parent 870f864 commit e26b406
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ describe('ExecutionService', () => {
*/
expect(waitTracker.stopExecution).not.toHaveBeenCalled();
expect(activeExecutions.stopExecution).toHaveBeenCalled();
expect(scalingService.findJobsByStatus).toHaveBeenCalled();
expect(scalingService.stopJob).toHaveBeenCalled();
expect(scalingService.findJobsByStatus).not.toHaveBeenCalled();
expect(scalingService.stopJob).not.toHaveBeenCalled();
expect(executionRepository.stopDuringRun).toHaveBeenCalled();
});

Expand All @@ -268,8 +268,8 @@ describe('ExecutionService', () => {
* Assert
*/
expect(waitTracker.stopExecution).toHaveBeenCalledWith(execution.id);
expect(scalingService.findJobsByStatus).toHaveBeenCalled();
expect(scalingService.stopJob).toHaveBeenCalled();
expect(scalingService.findJobsByStatus).not.toHaveBeenCalled();
expect(scalingService.stopJob).not.toHaveBeenCalled();
expect(executionRepository.stopDuringRun).toHaveBeenCalled();
});
});
Expand Down
14 changes: 1 addition & 13 deletions packages/cli/src/executions/execution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Workflow,
WorkflowOperationError,
} from 'n8n-workflow';
import { Container, Service } from 'typedi';
import { Service } from 'typedi';

import { ActiveExecutions } from '@/active-executions';
import { ConcurrencyControlService } from '@/concurrency/concurrency-control.service';
Expand Down Expand Up @@ -477,18 +477,6 @@ export class ExecutionService {
this.waitTracker.stopExecution(execution.id);
}

const { ScalingService } = await import('@/scaling/scaling.service');
const scalingService = Container.get(ScalingService);
const jobs = await scalingService.findJobsByStatus(['active', 'waiting']);

const job = jobs.find(({ data }) => data.executionId === execution.id);

if (job) {
await scalingService.stopJob(job);
} else {
this.logger.debug('Job to stop not in queue', { executionId: execution.id });
}

return await this.executionRepository.stopDuringRun(execution);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/workflow-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class WorkflowRunner {
//
// FIXME: This is a quick fix. The proper fix would be to not remove
// the execution from the active executions while it's still running.
if (error instanceof ExecutionNotFoundError) {
if (error instanceof ExecutionNotFoundError || error instanceof ExecutionCancelledError) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/error-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NodeOptions } from '@sentry/node';
import { close } from '@sentry/node';
import type { ErrorEvent, EventHint } from '@sentry/types';
import { AxiosError } from 'axios';
import { ApplicationError, type ReportingOptions } from 'n8n-workflow';
import { ApplicationError, ExecutionCancelledError, type ReportingOptions } from 'n8n-workflow';
import { createHash } from 'node:crypto';
import { Service } from 'typedi';

Expand Down Expand Up @@ -143,6 +143,7 @@ export class ErrorReporter {
}

error(e: unknown, options?: ReportingOptions) {
if (e instanceof ExecutionCancelledError) return;
const toReport = this.wrap(e);
if (toReport) this.report(toReport, options);
}
Expand Down

0 comments on commit e26b406

Please # to comment.