@pxp-nd/flow 1.0.26 → 1.0.28

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.
@@ -50,9 +50,15 @@ class FlowInstance extends core_1.Controller {
50
50
  flowInstanceIdProcessing = flowInstance.flowInstanceId;
51
51
  const node = await Node_1.default.findOne({ where: { actionId: flowInstance.actionId, flowId: flowInstance.flowId } });
52
52
  const CNodeInstance = new NodeInstance_1.default('flow-nd', NodeInstance_2.default);
53
- await CNodeInstance.RecursiveInstance({ node, flowInstance });
54
- flowInstance.status = 'processed';
55
- await manager.save(flowInstance);
53
+ try {
54
+ await CNodeInstance.RecursiveInstance({ node, flowInstance });
55
+ await manager.update(FlowInstance_1.default, { flowInstanceId: flowInstance.flowInstanceId }, { status: 'processed' });
56
+ }
57
+ catch (error) {
58
+ console.log(error);
59
+ await manager.update(FlowInstance_1.default, { flowInstanceId: flowInstance.flowInstanceId }, { status: 'error' });
60
+ }
61
+ await manager.update(FlowInstance_1.default, { flowInstanceId: flowInstance.flowInstanceId }, { status: 'processed' });
56
62
  }
57
63
  }
58
64
  catch (error) {
@@ -12,8 +12,8 @@
12
12
  * Created at : 2021-07-08 12:55:38
13
13
  * Last modified :
14
14
  */
15
- import { EntityManager } from 'typeorm';
16
- import { Controller } from '@pxp-nd/core';
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 !== '' || actionConfigJson !== '') {
54
- const actionConfigJsonObject = actionConfigJson && JSON.parse(lodash_1.default.template(actionConfigJson)(resultFromOrigin));
55
- const configJsonTemplateObject = configJsonTemplate && JSON.parse(lodash_1.default.template(configJsonTemplate)(resultFromOrigin));
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 === 'Y') {
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 = 'WAIT';
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: 'post',
80
+ method: "post",
79
81
  url: `http://localhost:${process.env.PORT}/api/${node.action.actionType.controller}`,
80
82
  headers: {
81
- 'Authorization': '' + process.env.TOKEN_PXP_ND + '',
82
- 'Content-Type': 'application/json'
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,57 +96,80 @@ 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({ node: nodeRes, flowInstance, resultFromOrigin });
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({ data: 'wf_processing_delay_nodes_flag' });
110
+ const flag = await common_1.GlobalData.findOne({
111
+ data: "wf_processing_delay_nodes_flag",
112
+ });
105
113
  if (flag) {
106
- if (flag.value == 'true') {
107
- throw new core_1.PxpError(400, 'Already processing pending flows');
114
+ if (flag.value == "true") {
115
+ throw new core_1.PxpError(400, "Already processing pending flows");
108
116
  }
109
- flag.value = 'true';
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({ data: 'wf_max_concurrent_delay_process' });
114
- const nodeInstanceDelayData = await core_1.__(manager.createQueryBuilder(NodeInstance_1.default, 'ni')
115
- .innerJoin(Node_1.default, 'n', 'n.nodeId = ni.nodeId')
116
- .innerJoin(Action_1.default, 'a', 'a.actionId = n.actionId')
117
- .innerJoin(ActionType_1.default, 'at', 'at.actionTypeId = a.actionTypeId')
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('ni.schedule <= :start ', { start: new Date() })
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: 'EXECUTING',
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) { // todo create transaction for own node
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
- await this.RecursiveInstance({ node: nodeRes, flowInstance, resultFromOrigin });
148
+ try {
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
+ }));
158
+ }
159
+ catch (error) {
160
+ await manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
161
+ status: "ERROR",
162
+ });
163
+ }
135
164
  }
136
- //update status from wait to executed
137
- await core_1.__(manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
138
- status: 'EXECUTED',
139
- }));
140
165
  }
141
166
  }
142
167
  catch (error) {
143
- flag.value = 'false';
168
+ flag.value = "false";
144
169
  await typeorm_1.getManager().save(flag);
145
- throw new core_1.PxpError(400, 'Error processing node: ' + nodeInstanceIdProcessing);
170
+ throw new core_1.PxpError(400, "Error processing node: " + nodeInstanceIdProcessing);
146
171
  }
147
- flag.value = 'false';
172
+ flag.value = "false";
148
173
  await typeorm_1.getManager().save(flag);
149
174
  }
150
175
  return { success: true };
@@ -152,7 +177,7 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
152
177
  };
153
178
  __decorate([
154
179
  core_1.Post(),
155
- core_1.DbSettings('Orm'),
180
+ core_1.DbSettings("Orm"),
156
181
  core_1.ReadOnly(false),
157
182
  core_1.Log(true),
158
183
  __metadata("design:type", Function),
@@ -160,6 +185,6 @@ __decorate([
160
185
  __metadata("design:returntype", Promise)
161
186
  ], NodeInstance.prototype, "ProcessDelay", null);
162
187
  NodeInstance = __decorate([
163
- core_1.Model('flow-nd/NodeInstance')
188
+ core_1.Model("flow-nd/NodeInstance")
164
189
  ], NodeInstance);
165
190
  exports.default = NodeInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",