From 5540a582f08de88d1df58c6d89dd95f17bc8d2ca Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 14 Jul 2023 17:37:09 +0700 Subject: [PATCH] fix(plugin-workflow): fix request node error in loop (#2254) --- .../__tests__/instructions/request.test.ts | 30 +++++++++++++++++++ .../src/server/instructions/request.ts | 3 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/plugins/workflow/src/server/__tests__/instructions/request.test.ts b/packages/plugins/workflow/src/server/__tests__/instructions/request.test.ts index 22cc5bbce..98cbab75a 100644 --- a/packages/plugins/workflow/src/server/__tests__/instructions/request.test.ts +++ b/packages/plugins/workflow/src/server/__tests__/instructions/request.test.ts @@ -213,5 +213,35 @@ describe('workflow > instructions > request', () => { expect(job.status).toEqual(JOB_STATUS.RESOLVED); expect(job.result.data).toEqual({ title }); }); + + it('request inside loop',async () => { + const n1 = await workflow.createNode({ + type: 'loop', + config: { + target: 2, + }, + }); + + const n2 = await workflow.createNode({ + type: 'request', + upstreamId: n1.id, + branchIndex: 0, + config: { + url: URL_DATA, + method: 'GET', + } + }); + + await PostRepo.create({ values: { title: 't1' } }); + + await sleep(500); + + const [execution] = await workflow.getExecutions(); + expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED); + const jobs = await execution.getJobs({ order: [['id', 'ASC']] }); + expect(jobs.length).toBe(3); + expect(jobs.map(item => item.status)).toEqual(Array(3).fill(JOB_STATUS.RESOLVED)); + expect(jobs[0].result).toBe(2); + }); }); }); diff --git a/packages/plugins/workflow/src/server/instructions/request.ts b/packages/plugins/workflow/src/server/instructions/request.ts index a3cab2e63..e2bea0b30 100644 --- a/packages/plugins/workflow/src/server/instructions/request.ts +++ b/packages/plugins/workflow/src/server/instructions/request.ts @@ -45,10 +45,11 @@ async function request(config) { export default class implements Instruction { constructor(public plugin) {} - async run(node: FlowNodeModel, input, processor: Processor) { + async run(node: FlowNodeModel, prevJob, processor: Processor) { const job = await processor.saveJob({ status: JOB_STATUS.PENDING, nodeId: node.id, + upstreamId: prevJob?.id ?? null, }); const config = processor.getParsedValue(node.config, node) as RequestConfig;