fix(core): Fix execution cancellation issues in scaling mode (#12343)

This commit is contained in:
Iván Ovejero 2024-12-30 13:17:55 +01:00 committed by GitHub
parent 870f8640c7
commit e26b406665
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 19 deletions

View file

@ -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();
});
@ -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();
});
});

View file

@ -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';
@ -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);
}

View file

@ -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;
}

View file

@ -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';
@ -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);
}