@pxp-nd/flow 1.0.27 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* Created at : 2021-07-08 12:55:38
|
|
13
13
|
* Last modified :
|
|
14
14
|
*/
|
|
15
|
-
import { EntityManager } from
|
|
16
|
-
import { Controller } from
|
|
15
|
+
import { EntityManager } from "typeorm";
|
|
16
|
+
import { Controller } from "@pxp-nd/core";
|
|
17
17
|
declare class NodeInstance extends Controller {
|
|
18
18
|
RecursiveInstance(params: Record<string, any>): Promise<unknown>;
|
|
19
19
|
ProcessDelay(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
@@ -49,14 +49,16 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
49
49
|
const resExecuteView = await core_1.__(typeorm_1.getManager().query(executeView));
|
|
50
50
|
const resultFromOrigin = resExecuteView[0];
|
|
51
51
|
let mergeJson = {};
|
|
52
|
-
const { actionConfigJson, action: { configJsonTemplate, actionType: { schemaJson } } } = node;
|
|
53
|
-
if (configJsonTemplate !==
|
|
54
|
-
const actionConfigJsonObject = actionConfigJson &&
|
|
55
|
-
|
|
52
|
+
const { actionConfigJson, action: { configJsonTemplate, actionType: { schemaJson }, }, } = node;
|
|
53
|
+
if (configJsonTemplate !== "" || actionConfigJson !== "") {
|
|
54
|
+
const actionConfigJsonObject = actionConfigJson &&
|
|
55
|
+
JSON.parse(lodash_1.default.template(actionConfigJson)(resultFromOrigin));
|
|
56
|
+
const configJsonTemplateObject = configJsonTemplate &&
|
|
57
|
+
JSON.parse(lodash_1.default.template(configJsonTemplate)(resultFromOrigin));
|
|
56
58
|
mergeJson = {
|
|
57
59
|
...(configJsonTemplateObject || {}),
|
|
58
60
|
...(actionConfigJsonObject || {}),
|
|
59
|
-
__resultFromOrigin: resultFromOrigin
|
|
61
|
+
__resultFromOrigin: resultFromOrigin,
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
64
|
let nodeInstance = new NodeInstance_1.default();
|
|
@@ -64,24 +66,24 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
64
66
|
// @ts-ignore
|
|
65
67
|
nodeInstance.nodeId = node.nodeId;
|
|
66
68
|
nodeInstance.runTime = new Date();
|
|
67
|
-
if (node.action.actionType.isDelay ===
|
|
69
|
+
if (node.action.actionType.isDelay === "Y") {
|
|
68
70
|
const delay = node.delay;
|
|
69
71
|
const typeDelay = node.typeDelay;
|
|
70
72
|
nodeInstance.schedule = moment_1.default().add(delay, typeDelay).toDate();
|
|
71
|
-
nodeInstance.status =
|
|
73
|
+
nodeInstance.status = "WAIT";
|
|
72
74
|
await typeorm_1.getManager().save(NodeInstance_1.default, nodeInstance);
|
|
73
75
|
}
|
|
74
76
|
else {
|
|
75
77
|
if (node.action.actionType.controller) {
|
|
76
|
-
const data =
|
|
78
|
+
const data = "";
|
|
77
79
|
const config = {
|
|
78
|
-
method:
|
|
80
|
+
method: "post",
|
|
79
81
|
url: `http://localhost:${process.env.PORT}/api/${node.action.actionType.controller}`,
|
|
80
82
|
headers: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
Authorization: "" + process.env.TOKEN_PXP_ND + "",
|
|
84
|
+
"Content-Type": "application/json",
|
|
83
85
|
},
|
|
84
|
-
data: mergeJson
|
|
86
|
+
data: mergeJson,
|
|
85
87
|
};
|
|
86
88
|
// @ts-ignore
|
|
87
89
|
const resControllerAxios = await core_1.__(axios_1.default(config));
|
|
@@ -94,64 +96,81 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
94
96
|
const evalCondition = eval(condition);
|
|
95
97
|
if (evalCondition) {
|
|
96
98
|
const nodeRes = await core_1.__(Node_1.default.findOne(nodeConnection.nodeIdChild));
|
|
97
|
-
await this.RecursiveInstance({
|
|
99
|
+
await this.RecursiveInstance({
|
|
100
|
+
node: nodeRes,
|
|
101
|
+
flowInstance,
|
|
102
|
+
resultFromOrigin,
|
|
103
|
+
});
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
return {};
|
|
102
108
|
}
|
|
103
109
|
async ProcessDelay(params, manager) {
|
|
104
|
-
const flag = await common_1.GlobalData.findOne({
|
|
110
|
+
const flag = await common_1.GlobalData.findOne({
|
|
111
|
+
data: "wf_processing_delay_nodes_flag",
|
|
112
|
+
});
|
|
105
113
|
if (flag) {
|
|
106
|
-
if (flag.value ==
|
|
107
|
-
throw new core_1.PxpError(400,
|
|
114
|
+
if (flag.value == "true") {
|
|
115
|
+
throw new core_1.PxpError(400, "Already processing pending flows");
|
|
108
116
|
}
|
|
109
|
-
flag.value =
|
|
117
|
+
flag.value = "true";
|
|
110
118
|
await typeorm_1.getManager().save(flag);
|
|
111
119
|
let nodeInstanceIdProcessing = -1;
|
|
112
120
|
try {
|
|
113
|
-
const maxNodes = await common_1.GlobalData.findOne({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
.
|
|
121
|
+
const maxNodes = await common_1.GlobalData.findOne({
|
|
122
|
+
data: "wf_max_concurrent_delay_process",
|
|
123
|
+
});
|
|
124
|
+
const nodeInstanceDelayData = await core_1.__(manager
|
|
125
|
+
.createQueryBuilder(NodeInstance_1.default, "ni")
|
|
126
|
+
.innerJoin(Node_1.default, "n", "n.nodeId = ni.nodeId")
|
|
127
|
+
.innerJoin(Action_1.default, "a", "a.actionId = n.actionId")
|
|
128
|
+
.innerJoin(ActionType_1.default, "at", "at.actionTypeId = a.actionTypeId")
|
|
118
129
|
.where("at.isDelay = 'Y' ")
|
|
119
|
-
.andWhere(
|
|
130
|
+
.andWhere("ni.schedule <= :start ", { start: new Date() })
|
|
120
131
|
.andWhere("ni.status = 'WAIT' ")
|
|
121
132
|
.limit((maxNodes && maxNodes.value))
|
|
122
133
|
.getMany());
|
|
123
134
|
for (const nodeInstance of nodeInstanceDelayData) {
|
|
124
135
|
//update status from wait to executing
|
|
125
136
|
await core_1.__(manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
|
|
126
|
-
status:
|
|
137
|
+
status: "EXECUTING",
|
|
138
|
+
}));
|
|
139
|
+
const nodeConnectionList = await core_1.__(NodeConnection_1.default.find({
|
|
140
|
+
where: { nodeIdMaster: nodeInstance.nodeId },
|
|
127
141
|
}));
|
|
128
|
-
const nodeConnectionList = await core_1.__(NodeConnection_1.default.find({ where: { nodeIdMaster: nodeInstance.nodeId } }));
|
|
129
142
|
const flowInstance = await core_1.__(FlowInstance_1.default.findOne(nodeInstance.flowInstanceId));
|
|
130
143
|
const resultFromOrigin = JSON.parse(flowInstance.resultFromOrigen);
|
|
131
144
|
// todo if in some transaction there is an error we need to put in some log to error and not try only some times
|
|
132
|
-
for (const nodeConnection of nodeConnectionList) {
|
|
145
|
+
for (const nodeConnection of nodeConnectionList) {
|
|
146
|
+
// todo create transaction for own node
|
|
133
147
|
const nodeRes = await core_1.__(Node_1.default.findOne(nodeConnection.nodeIdChild));
|
|
134
148
|
try {
|
|
135
|
-
await this.RecursiveInstance({
|
|
149
|
+
await this.RecursiveInstance({
|
|
150
|
+
node: nodeRes,
|
|
151
|
+
flowInstance,
|
|
152
|
+
resultFromOrigin,
|
|
153
|
+
});
|
|
154
|
+
//update status from wait to executed
|
|
155
|
+
await core_1.__(manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
|
|
156
|
+
status: "EXECUTED",
|
|
157
|
+
}));
|
|
136
158
|
}
|
|
137
159
|
catch (error) {
|
|
160
|
+
console.log(error);
|
|
138
161
|
await manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
|
|
139
|
-
status:
|
|
162
|
+
status: "ERROR",
|
|
140
163
|
});
|
|
141
164
|
}
|
|
142
165
|
}
|
|
143
|
-
//update status from wait to executed
|
|
144
|
-
await core_1.__(manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
|
|
145
|
-
status: 'EXECUTED',
|
|
146
|
-
}));
|
|
147
166
|
}
|
|
148
167
|
}
|
|
149
168
|
catch (error) {
|
|
150
|
-
flag.value =
|
|
169
|
+
flag.value = "false";
|
|
151
170
|
await typeorm_1.getManager().save(flag);
|
|
152
|
-
throw new core_1.PxpError(400,
|
|
171
|
+
throw new core_1.PxpError(400, "Error processing node: " + nodeInstanceIdProcessing);
|
|
153
172
|
}
|
|
154
|
-
flag.value =
|
|
173
|
+
flag.value = "false";
|
|
155
174
|
await typeorm_1.getManager().save(flag);
|
|
156
175
|
}
|
|
157
176
|
return { success: true };
|
|
@@ -159,7 +178,7 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
159
178
|
};
|
|
160
179
|
__decorate([
|
|
161
180
|
core_1.Post(),
|
|
162
|
-
core_1.DbSettings(
|
|
181
|
+
core_1.DbSettings("Orm"),
|
|
163
182
|
core_1.ReadOnly(false),
|
|
164
183
|
core_1.Log(true),
|
|
165
184
|
__metadata("design:type", Function),
|
|
@@ -167,6 +186,6 @@ __decorate([
|
|
|
167
186
|
__metadata("design:returntype", Promise)
|
|
168
187
|
], NodeInstance.prototype, "ProcessDelay", null);
|
|
169
188
|
NodeInstance = __decorate([
|
|
170
|
-
core_1.Model(
|
|
189
|
+
core_1.Model("flow-nd/NodeInstance")
|
|
171
190
|
], NodeInstance);
|
|
172
191
|
exports.default = NodeInstance;
|