Skip to content

Commit 965ea25

Browse files
guillaumejacquartCadiac
authored andcommitted
fix(core): Resolves response promise for active execution on job finished in queue mode (n8n-io#15643)
Co-authored-by: Jaakko Husso <[email protected]>
1 parent 2fa25f6 commit 965ea25

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

packages/cli/src/scaling/scaling.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ export class ScalingService {
305305
this.activeExecutions.resolveResponsePromise(msg.executionId, decodedResponse);
306306
break;
307307
case 'job-finished':
308+
this.activeExecutions.resolveResponsePromise(msg.executionId, {});
308309
this.logger.info(`Execution ${msg.executionId} (job ${jobId}) finished successfully`, {
309310
workerId: msg.workerId,
310311
executionId: msg.executionId,

packages/cli/src/webhooks/__tests__/webhook-helpers.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ describe('autoDetectResponseMode', () => {
6565
expect(result).toBe('responseNode');
6666
});
6767

68+
test('should return formPage when start node is FORM_NODE_TYPE and method is POST and there is a following FORM_NODE_TYPE node', () => {
69+
const workflowStartNode = mock<INode>({
70+
type: FORM_NODE_TYPE,
71+
name: 'startNode',
72+
parameters: {},
73+
});
74+
workflow.getChildNodes.mockReturnValue(['childNode']);
75+
workflow.nodes.childNode = mock<INode>({
76+
type: FORM_NODE_TYPE,
77+
parameters: {
78+
operation: 'completion',
79+
},
80+
disabled: false,
81+
});
82+
const result = autoDetectResponseMode(workflowStartNode, workflow, 'POST');
83+
expect(result).toBe('formPage');
84+
});
85+
6886
test('should return undefined when start node is FORM_NODE_TYPE with no other form child nodes', () => {
6987
const workflowStartNode = mock<INode>({
7088
type: FORM_NODE_TYPE,

packages/cli/src/webhooks/webhook-helpers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export function getWorkflowWebhooks(
105105
return returnData;
106106
}
107107

108+
// eslint-disable-next-line complexity
108109
export function autoDetectResponseMode(
109110
workflowStartNode: INode,
110111
workflow: Workflow,
@@ -126,6 +127,21 @@ export function autoDetectResponseMode(
126127
}
127128
}
128129

130+
// If there are form nodes connected to a current form node we're dealing with a multipage form
131+
// and we need to return the formPage response mode when a second page of the form gets submitted
132+
// to be able to show potential form errors correctly.
133+
if (workflowStartNode.type === FORM_NODE_TYPE && method === 'POST') {
134+
const connectedNodes = workflow.getChildNodes(workflowStartNode.name);
135+
136+
for (const nodeName of connectedNodes) {
137+
const node = workflow.nodes[nodeName];
138+
139+
if (node.type === FORM_NODE_TYPE && !node.disabled) {
140+
return 'formPage';
141+
}
142+
}
143+
}
144+
129145
if (workflowStartNode.type === WAIT_NODE_TYPE && workflowStartNode.parameters.resume !== 'form') {
130146
return undefined;
131147
}

packages/cli/templates/form-trigger.handlebars

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,7 @@
857857
document.querySelector('#submit-btn span').style.display = 'inline-block';
858858
859859
let postUrl = '';
860-
if (window.location.href.includes('form-waiting')) {
861-
intervalId = setTimeout(checkExecutionStatus, interval);
862-
} else {
860+
if (!window.location.href.includes('form-waiting')) {
863861
postUrl = window.location.search;
864862
}
865863
@@ -880,7 +878,8 @@
880878
881879
if(json?.formWaitingUrl) {
882880
formWaitingUrl = json.formWaitingUrl;
883-
intervalId = setTimeout(checkExecutionStatus, interval);
881+
clearTimeout(timeoutId);
882+
timeoutId = setTimeout(checkExecutionStatus, interval);
884883
return;
885884
}
886885
@@ -934,6 +933,12 @@
934933
})
935934
.catch(function (error) {
936935
console.error('Error:', error);
936+
})
937+
.finally(() => {
938+
if (window.location.href.includes('form-waiting')) {
939+
clearTimeout(timeoutId);
940+
timeoutId = setTimeout(checkExecutionStatus, interval);
941+
}
937942
});
938943
}
939944
});

0 commit comments

Comments
 (0)