diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/src/server/DelayInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-delay/src/server/DelayInstruction.ts index 21a748c59..9d761bd5a 100644 --- a/packages/plugins/@nocobase/plugin-workflow-delay/src/server/DelayInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-delay/src/server/DelayInstruction.ts @@ -91,6 +91,7 @@ export default class extends Instruction { status: JOB_STATUS.PENDING, result: null, nodeId: node.id, + nodeKey: node.key, upstreamId: prevJob?.id ?? null, }); job.node = node; diff --git a/packages/plugins/@nocobase/plugin-workflow-loop/src/server/LoopInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-loop/src/server/LoopInstruction.ts index f090d3d82..cf3999308 100644 --- a/packages/plugins/@nocobase/plugin-workflow-loop/src/server/LoopInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-loop/src/server/LoopInstruction.ts @@ -32,6 +32,7 @@ export default class extends Instruction { // save loop index result: 0, nodeId: node.id, + nodeKey: node.key, upstreamId: prevJob?.id ?? null, }); diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/ManualInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/ManualInstruction.ts index 5d74b1869..d1f66c1f1 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/ManualInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/ManualInstruction.ts @@ -99,6 +99,7 @@ export default class extends Instruction { status: JOB_STATUS.PENDING, result: mode ? [] : null, nodeId: node.id, + nodeKey: node.key, upstreamId: prevJob?.id ?? null, }); 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 5f5a69469..938be32b1 100644 --- a/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/ParallelInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-parallel/src/server/ParallelInstruction.ts @@ -61,6 +61,7 @@ export default class extends Instruction { status: JOB_STATUS.PENDING, result: Array(branches.length).fill(null), nodeId: node.id, + nodeKey: node.key, upstreamId: prevJob?.id ?? null, }); diff --git a/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts index 1db953afb..9d3d215d0 100644 --- a/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-request/src/server/RequestInstruction.ts @@ -44,6 +44,7 @@ export default class extends Instruction { const job = await processor.saveJob({ status: JOB_STATUS.PENDING, nodeId: node.id, + nodeKey: node.key, upstreamId: prevJob?.id ?? null, }); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts index f8ddb1afa..0cae71471 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts @@ -139,6 +139,7 @@ export default class Processor { if (!(job instanceof Model)) { job.upstreamId = prevJob instanceof Model ? prevJob.get('id') : null; job.nodeId = node.id; + job.nodeKey = node.key; } const savedJob = await this.saveJob(job); @@ -222,8 +223,7 @@ export default class Processor { } this.jobsMap.set(job.id, job); - const node = this.nodesMap.get(job.nodeId); - this.jobsMapByNodeKey[node.key] = job.result; + this.jobsMapByNodeKey[job.nodeKey] = job.result; return job; } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/ConditionInstruction.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/ConditionInstruction.ts index bd59b4e7a..fb84f92e0 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/ConditionInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/ConditionInstruction.ts @@ -152,6 +152,7 @@ export class ConditionInstruction extends Instruction { result, // TODO(optimize): try unify the building of job nodeId: node.id, + nodeKey: node.key, upstreamId: (prevJob && prevJob.id) || null, }; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts index 034e15688..b24a2f6d0 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts @@ -20,7 +20,7 @@ export default class extends Migration { } return job.update( { - nodeKey: job.node.key, + nodeKey: job.node?.key, }, { silent: true,