Skip to content

Commit 6353bf7

Browse files
committed
Fix _parent on chaing workflow instance
1 parent 62d3e86 commit 6353bf7

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

OpenFlow/src/Messages/Message.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,10 @@ export class Message {
25092509
if (!msg.initialrun) {
25102510
(_data as any).form = "unknown";
25112511
}
2512+
if ((_data as any).payload._parentid) {
2513+
(_data as any)._parentid = (_data as any).payload._parentid;
2514+
delete (_data as any).payload._parentid;
2515+
}
25122516

25132517
const res2 = await Config.db.InsertOne(_data, "workflow_instances", 1, true, msg.jwt, span);
25142518
msg.newinstanceid = res2._id;

OpenFlowNodeRED/src/nodered/nodes/workflow_nodes.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,15 +587,15 @@ export class assign_workflow_node {
587587
}
588588
}
589589
if (_id !== null && _id !== undefined && _id !== "") {
590-
const res = await NoderedUtil.Query({ collectionname: "workflow_instances", query: { "_id": _id }, projection: { parentid: 1 }, top: 1, jwt: data.jwt, priority });
590+
const res = await NoderedUtil.Query({ collectionname: "workflow_instances", query: { "_id": _id }, projection: { "_parentid": 1 }, top: 1, jwt: data.jwt, priority });
591591
if (res.length == 0) {
592592
NoderedUtil.HandleError(this, "Unknown workflow_instances id " + _id, msg);
593593
if (ack !== null && ack !== undefined) ack();
594594
return;
595595
}
596596
const currentinstance = res[0];
597597
const state = res[0].state;
598-
const _parentid = res[0].parentid;
598+
const _parentid = res[0]._parentid;
599599
if (_parentid !== null && _parentid !== undefined && _parentid !== "") {
600600
const res2 = await NoderedUtil.Query({ collectionname: "workflow_instances", query: { "_id": _parentid }, top: 1, priority });
601601
if (res2.length == 0) {
@@ -612,8 +612,14 @@ export class assign_workflow_node {
612612
result.user = data.user;
613613
this.node.send([null, result]);
614614
if (ack !== null && ack !== undefined) ack();
615-
// await NoderedUtil.UpdateOne("workflow_instances", null, res[0], 1, false, null);
615+
await NoderedUtil.UpdateOne({ collectionname: "workflow_instances", query: { _id: _parentid }, item: { "$set": { "state": "completed" } } })
616616
return;
617+
} else {
618+
const res = await NoderedUtil.Query({ collectionname: "workflow_instances", query: { "_id": _id }, projection: { msg: 1 }, top: 1, jwt: data.jwt, priority });
619+
if (res.length > 0 && res[0].msg) {
620+
result = res[0].msg;
621+
result.state = data.state;
622+
}
617623
}
618624
}
619625
result.payload = data.payload;
@@ -697,6 +703,7 @@ export class assign_workflow_node {
697703

698704
const res3 = await NoderedUtil.InsertOne({ collectionname: "workflow_instances", item: runnerinstance, jwt, priority });
699705
msg._parentid = res3._id;
706+
msg.payload._parentid = res3._id;
700707

701708
// parentid: res3._id,
702709
msg.newinstanceid = await NoderedUtil.CreateWorkflowInstance({ targetid, workflowid, resultqueue: this.localqueue, data: msg.payload, initialrun, jwt, priority });

0 commit comments

Comments
 (0)