From a275ebab34eee9a184f82320991ff7cf8c25d7dd Mon Sep 17 00:00:00 2001 From: Junyi Date: Tue, 26 Aug 2025 10:46:51 +0800 Subject: [PATCH] fix(plugin-workflow-parallel): fix branch status bug (#7445) * fix(plugin-workflow-parallel): fix branch status bug * fix(plugin-workflow-parallel): fix locale --- .../src/client/ParallelInstruction.tsx | 2 +- .../src/locale/zh-CN.json | 2 +- .../src/server/ParallelInstruction.ts | 2 +- .../src/server/__tests__/instruction.test.ts | 51 +++++++++++++++++++ .../src/server/instructions.ts | 2 +- 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-workflow-parallel/src/client/ParallelInstruction.tsx b/packages/plugins/@nocobase/plugin-workflow-parallel/src/client/ParallelInstruction.tsx index 6a2f8321977..cb826e8eddb 100644 --- a/packages/plugins/@nocobase/plugin-workflow-parallel/src/client/ParallelInstruction.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-parallel/src/client/ParallelInstruction.tsx @@ -152,7 +152,7 @@ export default class extends Instruction { }, { value: 'allSettled', - label: `{{t('Run all branch (ignore failures)', { ns: "${NAMESPACE}" })}}`, + label: `{{t('Run all branches (ignore failures)', { ns: "${NAMESPACE}" })}}`, tooltip: `{{t('Always continue after all branches end, regardless of success or failure.', { ns: "${NAMESPACE}" })}}`, }, ], diff --git a/packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/zh-CN.json index 9c4b483607f..21fa43c72f9 100644 --- a/packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/zh-CN.json @@ -6,7 +6,7 @@ "All succeeded": "全部成功", "Any succeeded": "任意成功", "Any succeeded or failed": "任意成功或失败", - "Run all branch (ignore failures)": "全部执行(忽略失败)", + "Run all branches (ignore failures)": "全部执行(忽略失败)", "Continue after all branches succeeded": "全部分支都成功后才能继续", "Continue after any branch succeeded": "任意分支成功后就继续", "Continue after any branch succeeded, or exit after any branch failed.": "任意分支成功就继续流程,或者任意分支失败就退出流程。", diff --git a/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/ParallelInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/ParallelInstruction.ts index a497aba56d0..8f58172b07f 100644 --- a/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/ParallelInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/ParallelInstruction.ts @@ -66,7 +66,7 @@ const Modes = { return true; }, getStatus(result) { - if (result.some((status) => status === JOB_STATUS.PENDING)) { + if (result.some((status) => !status)) { return JOB_STATUS.PENDING; } return JOB_STATUS.RESOLVED; diff --git a/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/__tests__/instruction.test.ts b/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/__tests__/instruction.test.ts index c289ca4cfff..2e55d54984a 100644 --- a/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/__tests__/instruction.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/__tests__/instruction.test.ts @@ -329,6 +329,57 @@ describe('workflow > instructions > parallel', () => { expect(jobs.find((item) => item.nodeId === n2.id).status).toBe(JOB_STATUS.RESOLVED); expect(jobs.find((item) => item.nodeId === n3.id).status).toBe(JOB_STATUS.ERROR); }); + + it('wait till all done', async () => { + const n1 = await workflow.createNode({ + type: 'parallel', + config: { + mode: 'allSettled', + }, + }); + const n2 = await workflow.createNode({ + type: 'echo', + upstreamId: n1.id, + branchIndex: 0, + }); + const n3 = await workflow.createNode({ + type: 'asyncResume', + config: { + duration: 500, + }, + upstreamId: n1.id, + branchIndex: 1, + }); + const n4 = await workflow.createNode({ + type: 'echo', + upstreamId: n3.id, + }); + await n3.setDownstream(n4); + + const post = await PostRepo.create({ values: { title: 't1' } }); + + await sleep(300); + + const [e1] = await workflow.getExecutions(); + expect(e1.status).toBe(EXECUTION_STATUS.STARTED); + const j1s = await e1.getJobs({ order: [['id', 'ASC']] }); + expect(j1s.length).toBe(3); + expect(j1s.find((item) => item.nodeId === n1.id).status).toBe(JOB_STATUS.PENDING); + expect(j1s.find((item) => item.nodeId === n1.id).result).toEqual([JOB_STATUS.RESOLVED, null]); + expect(j1s.find((item) => item.nodeId === n2.id).status).toBe(JOB_STATUS.RESOLVED); + expect(j1s.find((item) => item.nodeId === n3.id).status).toBe(JOB_STATUS.PENDING); + + await sleep(300); + + const [e2] = await workflow.getExecutions(); + expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED); + const j2s = await e2.getJobs({ order: [['id', 'ASC']] }); + expect(j2s.length).toBe(4); + expect(j2s.find((item) => item.nodeId === n1.id).status).toBe(JOB_STATUS.RESOLVED); + expect(j2s.find((item) => item.nodeId === n2.id).status).toBe(JOB_STATUS.RESOLVED); + expect(j2s.find((item) => item.nodeId === n3.id).status).toBe(JOB_STATUS.RESOLVED); + expect(j2s.find((item) => item.nodeId === n4.id).status).toBe(JOB_STATUS.RESOLVED); + }); }); describe('branch and join', () => { diff --git a/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts b/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts index 66dc259fd47..3477403ab4b 100644 --- a/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts +++ b/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts @@ -100,7 +100,7 @@ export default { }); processor.options.plugin.resume(job); - }, 100); + }, node.config.duration ?? 100); return null; },