mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Use AbortController to notify nodes to abort execution (#6141)
and add support for cancelling ongoing operations inside a node. --------- Co-authored-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
committed by
GitHub
parent
0ec67dabf7
commit
d2c18c5727
@@ -2508,6 +2508,19 @@ const getCommonWorkflowFunctions = (
|
||||
prepareOutputData: async (outputData) => [outputData],
|
||||
});
|
||||
|
||||
const executionCancellationFunctions = (
|
||||
abortSignal?: AbortSignal,
|
||||
): Pick<IExecuteFunctions, 'onExecutionCancellation' | 'getExecutionCancelSignal'> => ({
|
||||
getExecutionCancelSignal: () => abortSignal,
|
||||
onExecutionCancellation: (handler) => {
|
||||
const fn = () => {
|
||||
abortSignal?.removeEventListener('abort', fn);
|
||||
handler();
|
||||
};
|
||||
abortSignal?.addEventListener('abort', fn);
|
||||
},
|
||||
});
|
||||
|
||||
const getRequestHelperFunctions = (
|
||||
workflow: Workflow,
|
||||
node: INode,
|
||||
@@ -3087,10 +3100,12 @@ export function getExecuteFunctions(
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
executeData: IExecuteData,
|
||||
mode: WorkflowExecuteMode,
|
||||
abortSignal?: AbortSignal,
|
||||
): IExecuteFunctions {
|
||||
return ((workflow, runExecutionData, connectionInputData, inputData, node) => {
|
||||
return {
|
||||
...getCommonWorkflowFunctions(workflow, node, additionalData),
|
||||
...executionCancellationFunctions(abortSignal),
|
||||
getMode: () => mode,
|
||||
getCredentials: async (type, itemIndex) =>
|
||||
getCredentials(
|
||||
@@ -3512,10 +3527,12 @@ export function getExecuteSingleFunctions(
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
executeData: IExecuteData,
|
||||
mode: WorkflowExecuteMode,
|
||||
abortSignal?: AbortSignal,
|
||||
): IExecuteSingleFunctions {
|
||||
return ((workflow, runExecutionData, connectionInputData, inputData, node, itemIndex) => {
|
||||
return {
|
||||
...getCommonWorkflowFunctions(workflow, node, additionalData),
|
||||
...executionCancellationFunctions(abortSignal),
|
||||
continueOnFail: () => continueOnFail(node),
|
||||
evaluateExpression: (expression: string, evaluateItemIndex: number | undefined) => {
|
||||
evaluateItemIndex = evaluateItemIndex === undefined ? itemIndex : evaluateItemIndex;
|
||||
|
||||
Reference in New Issue
Block a user