Compare commits

...

2 commits

Author SHA1 Message Date
Danny Martini e9fd2be0b3
Revert "report ExecutionNotFoundError only to sentry and the logs, not to the user"
This reverts commit 9b0b0fbf57.
2024-09-19 17:36:25 +02:00
Danny Martini f19fcb2c0b
Revert "getExecution can now return undefined if there is no active execution for that id"
This reverts commit 047b1d13c0.
2024-09-19 17:36:25 +02:00
2 changed files with 15 additions and 40 deletions

View file

@ -5,12 +5,7 @@ import type {
ExecutionStatus,
IWorkflowExecutionDataProcess,
} from 'n8n-workflow';
import {
createDeferredPromise,
ErrorReporterProxy,
ExecutionCancelledError,
sleep,
} from 'n8n-workflow';
import { createDeferredPromise, ExecutionCancelledError, sleep } from 'n8n-workflow';
import { strict as assert } from 'node:assert';
import type PCancelable from 'p-cancelable';
import { Service } from 'typedi';
@ -127,20 +122,14 @@ export class ActiveExecutions {
*/
attachWorkflowExecution(executionId: string, workflowExecution: PCancelable<IRun>) {
const execution = this.getExecution(executionId);
if (execution) {
execution.workflowExecution = workflowExecution;
}
this.getExecution(executionId).workflowExecution = workflowExecution;
}
attachResponsePromise(
executionId: string,
responsePromise: IDeferredPromise<IExecuteResponsePromiseData>,
): void {
const execution = this.getExecution(executionId);
if (execution) {
execution.responsePromise = responsePromise;
}
this.getExecution(executionId).responsePromise = responsePromise;
}
resolveResponsePromise(executionId: string, response: IExecuteResponsePromiseData): void {
@ -151,31 +140,23 @@ export class ActiveExecutions {
/** Cancel the execution promise and reject its post-execution promise. */
stopExecution(executionId: string): void {
const execution = this.getExecution(executionId);
if (execution) {
execution.workflowExecution?.cancel();
execution.postExecutePromise.reject(new ExecutionCancelledError(executionId));
this.logger.debug('Execution cancelled', { executionId });
}
execution.workflowExecution?.cancel();
execution.postExecutePromise.reject(new ExecutionCancelledError(executionId));
this.logger.debug('Execution cancelled', { executionId });
}
/** Resolve the post-execution promise in an execution. */
finalizeExecution(executionId: string, fullRunData?: IRun) {
const execution = this.getExecution(executionId);
if (execution) {
execution.postExecutePromise.resolve(fullRunData);
this.logger.debug('Execution finalized', { executionId });
}
execution.postExecutePromise.resolve(fullRunData);
this.logger.debug('Execution finalized', { executionId });
}
/**
* Returns a promise which will resolve with the data of the execution with the given id
*/
async getPostExecutePromise(executionId: string): Promise<IRun | undefined> {
const execution = this.getExecution(executionId);
if (execution) {
return await execution.postExecutePromise.promise;
}
return undefined;
return await this.getExecution(executionId).postExecutePromise.promise;
}
/**
@ -202,14 +183,11 @@ export class ActiveExecutions {
}
setStatus(executionId: string, status: ExecutionStatus) {
const execution = this.getExecution(executionId);
if (execution) {
execution.status = status;
}
this.getExecution(executionId).status = status;
}
getStatus(executionId: string): ExecutionStatus | undefined {
return this.getExecution(executionId)?.status;
getStatus(executionId: string): ExecutionStatus {
return this.getExecution(executionId).status;
}
/** Wait for all active executions to finish */
@ -241,10 +219,10 @@ export class ActiveExecutions {
}
}
private getExecution(executionId: string): IExecutingWorkflowData | undefined {
private getExecution(executionId: string): IExecutingWorkflowData {
const execution = this.activeExecutions[executionId];
if (!execution) {
ErrorReporterProxy.error(new ExecutionNotFoundError(executionId));
throw new ExecutionNotFoundError(executionId);
}
return execution;
}

View file

@ -334,10 +334,7 @@ export class WorkflowRunner {
if (workflowExecution.isCanceled) {
fullRunData.finished = false;
}
const status = this.activeExecutions.getStatus(executionId);
if (status) {
fullRunData.status = status;
}
fullRunData.status = this.activeExecutions.getStatus(executionId);
this.activeExecutions.finalizeExecution(executionId, fullRunData);
})
.catch(