@5minds/node-red-contrib-processcube 0.14.0-feature-c8461c-lyxixqqm → 0.14.0-feature-a07566-lyy11h2t

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module.exports = function(RED) {
8
8
 
9
9
  node.on('input', function(msg) {
10
10
 
11
- const externalTaskId = msg.externalTaskId;
11
+ const flowNodeInstanceId = msg.flowNodeInstanceId;
12
12
 
13
13
  let msgError = msg.error;
14
14
 
@@ -26,7 +26,7 @@ module.exports = function(RED) {
26
26
  // TODO: hack cause https://github.com/5minds/ProcessCube.Engine.Client.ts/blob/develop/src/ExternalTaskWorker.ts#L180
27
27
  error.stack = RED.util.encodeObject(msg);
28
28
 
29
- eventEmitter.emit(`handle-${externalTaskId}`, error, true);
29
+ eventEmitter.emit(`handle-${flowNodeInstanceId}`, error, true);
30
30
 
31
31
  node.send(msg);
32
32
  });
@@ -30,13 +30,21 @@ module.exports = function(RED) {
30
30
  client.externalTasks.subscribeToExternalTaskTopic(
31
31
  config.topic,
32
32
  async (payload, externalTask) => {
33
+
34
+ const saveHandleCallback = (data, callback) => {
35
+ try {
36
+ callback(data);
37
+ } catch (error) {
38
+ node.error(`Error in callback 'saveHandleCallback': ${error.message}`);
39
+ }
40
+ };
33
41
 
34
42
  return await new Promise((resolve, reject) => {
35
43
 
36
44
  const handleFinishTask = (msg) => {
37
45
  let result = RED.util.encodeObject(msg.payload);
38
46
 
39
- node.log(`handle event for external task ${externalTask.flowNodeInstanceId} and process it with result ${result} on msg._msgid ${msg._msgid}.`);
47
+ node.log(`handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* ${externalTask.processInstanceId} with result ${result} on msg._msgid ${msg._msgid}.`);
40
48
 
41
49
  if (externalTask.flowNodeInstanceId) {
42
50
  delete started_external_tasks[externalTask.flowNodeInstanceId];
@@ -45,12 +53,13 @@ module.exports = function(RED) {
45
53
  showStatus(node, Object.keys(started_external_tasks).length);
46
54
 
47
55
 
48
- resolve(result);
56
+ //resolve(result);
57
+ saveHandleCallback(result,resolve)
49
58
  };
50
59
 
51
60
  const handleErrorTask = (msg) => {
52
61
 
53
- node.log(`handle error event for external task ${externalTask.flowNodeInstanceId} with result ${msg} on msg._msgid ${msg._msgid}.`);
62
+ node.log(`handle error event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' on *msg._msgid* '${msg._msgid}'.`);
54
63
 
55
64
  if (externalTask.flowNodeInstanceId) {
56
65
  delete started_external_tasks[externalTask.flowNodeInstanceId];
@@ -62,11 +71,12 @@ module.exports = function(RED) {
62
71
  // TODO: with reject, the default error handling is proceed
63
72
  // SEE: https://github.com/5minds/ProcessCube.Engine.Client.ts/blob/develop/src/ExternalTaskWorker.ts#L180
64
73
  // reject(result);
65
- resolve(msg);
74
+ //resolve(msg);
75
+ saveHandleCallback(msg,resolve);
66
76
  };
67
77
 
68
78
  eventEmitter.once(`handle-${externalTask.flowNodeInstanceId}`, (msg, isError = false) => {
69
- node.log(`handle event for external task ${externalTask.flowNodeInstanceId} and process it with msg._msgid ${msg._msgid} and isError ${isError}`);
79
+ node.log(`handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}' and *isError* '${isError}'`);
70
80
 
71
81
  if (isError) {
72
82
  handleErrorTask(msg);
@@ -81,12 +91,12 @@ module.exports = function(RED) {
81
91
 
82
92
  let msg = {
83
93
  _msgid: RED.util.generateId(),
84
- topic: externalTask.topic,
94
+ task: RED.util.encodeObject(externalTask),
85
95
  payload: payload,
86
- externalTaskId: externalTask.flowNodeInstanceId
96
+ flowNodeInstanceId: externalTask.flowNodeInstanceId
87
97
  };
88
98
 
89
- node.log(`Received external task ${externalTask.flowNodeInstanceId} and process it with msg._msgid ${msg._msgid}`);
99
+ node.log(`Received *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}'`);
90
100
 
91
101
  node.send(msg);
92
102
  });
@@ -105,7 +115,7 @@ module.exports = function(RED) {
105
115
  case 'extendLock':
106
116
  case 'finishExternalTask':
107
117
  case 'processExternalTask':
108
- node.error(`Worker error ${errorType} for external task ${externalTask.flowNodeInstanceId}: ${error.message}`);
118
+ node.error(`Worker error ${errorType} for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}': ${error.message}`);
109
119
 
110
120
  externalTaskWorker.stop();
111
121
 
@@ -121,7 +131,11 @@ module.exports = function(RED) {
121
131
  }
122
132
  });
123
133
 
124
- externalTaskWorker.start();
134
+ try {
135
+ externalTaskWorker.start();
136
+ } catch (error) {
137
+ node.error(`Worker start 'externalTaskWorker.start' failed: ${error.message}`);
138
+ }
125
139
 
126
140
  node.on("close", () => {
127
141
  try {
@@ -8,13 +8,13 @@ module.exports = function(RED) {
8
8
 
9
9
  node.on('input', function(msg) {
10
10
 
11
- const externalTaskId = msg.externalTaskId;
11
+ const flowNodeInstanceId = msg.flowNodeInstanceId;
12
12
 
13
- if (!externalTaskId) {
13
+ if (!flowNodeInstanceId) {
14
14
  node.error('Error: The message did not contain the required external task id.', msg);
15
15
  }
16
16
 
17
- eventEmitter.emit(`handle-${externalTaskId}`, msg, false);
17
+ eventEmitter.emit(`handle-${flowNodeInstanceId}`, msg, false);
18
18
  });
19
19
  }
20
20
  RED.nodes.registerType("externaltask-output", ExternalTaskOutput);
@@ -210,7 +210,7 @@
210
210
  "g": "31cb6729aac0ba46",
211
211
  "name": "",
212
212
  "pauseType": "delay",
213
- "timeout": "5",
213
+ "timeout": "15",
214
214
  "timeoutUnits": "seconds",
215
215
  "rate": "1",
216
216
  "nbRateUnits": "1",
@@ -221,7 +221,7 @@
221
221
  "drop": false,
222
222
  "allowrate": false,
223
223
  "outputs": 1,
224
- "x": 320,
224
+ "x": 330,
225
225
  "y": 360,
226
226
  "wires": [
227
227
  [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "0.14.0-feature-c8461c-lyxixqqm",
3
+ "version": "0.14.0-feature-a07566-lyy11h2t",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "authors": [