From ad065431fbc0bfe8d4f5c5aef5a584c3e9bc1c16 Mon Sep 17 00:00:00 2001 From: Junyi Date: Mon, 29 Jan 2024 14:04:37 +0800 Subject: [PATCH] fix(plugin-workflow): fix end logic when success (#3453) --- .../plugin-workflow/src/client/style.tsx | 3 +-- .../server/__tests__/instructions/end.test.ts | 24 +++++++++++++++---- .../src/server/instructions/EndInstruction.ts | 13 ++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/style.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/style.tsx index 3f429c4ae7..c2ed96e9d1 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/style.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/style.tsx @@ -200,8 +200,7 @@ const useStyles = createStyles(({ css, token }) => { align-items: center; justify-content: center; width: 0; - height: 4em; - padding: 1em 0; + height: 6em; border-left: 1px dashed ${token.colorBgLayout}; .anticon { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/end.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/end.test.ts index ace3ae4cc0..2474d32c78 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/end.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/end.test.ts @@ -35,12 +35,20 @@ describe('workflow > instructions > end', () => { }, }); + const n2 = await workflow.createNode({ + type: 'echo', + upstreamId: n1.id, + }); + + await n1.setDownstream(n2); + await plugin.trigger(workflow, {}); const [execution] = await workflow.getExecutions(); expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED); - const [job] = await execution.getJobs(); - expect(job.status).toBe(JOB_STATUS.RESOLVED); + const jobs = await execution.getJobs(); + expect(jobs.length).toBe(1); + expect(jobs[0].status).toBe(JOB_STATUS.RESOLVED); }); it('failed', async () => { @@ -51,12 +59,20 @@ describe('workflow > instructions > end', () => { }, }); + const n2 = await workflow.createNode({ + type: 'echo', + upstreamId: n1.id, + }); + + await n1.setDownstream(n2); + await plugin.trigger(workflow, {}); const [execution] = await workflow.getExecutions(); expect(execution.status).toBe(EXECUTION_STATUS.FAILED); - const [job] = await execution.getJobs(); - expect(job.status).toBe(JOB_STATUS.FAILED); + const jobs = await execution.getJobs(); + expect(jobs.length).toBe(1); + expect(jobs[0].status).toBe(JOB_STATUS.FAILED); }); }); }); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/EndInstruction.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/EndInstruction.ts index 23d401d43f..f0cd103d39 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/EndInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/EndInstruction.ts @@ -9,9 +9,14 @@ interface Config { export default class extends Instruction { async run(node: FlowNodeModel, prevJob, processor: Processor) { - const { endStatus } = node.config; - return { - status: endStatus ?? JOB_STATUS.RESOLVED, - }; + const { endStatus = JOB_STATUS.RESOLVED } = node.config; + await processor.saveJob({ + status: endStatus, + nodeId: node.id, + nodeKey: node.key, + upstreamId: prevJob?.id ?? null, + }); + + return processor.exit(endStatus); } }