@5minds/node-red-contrib-processcube 0.14.0-fix-error-in-process-instance-query-433395-lyzh0xul → 0.14.0

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.
package/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:20 as builder
1
+ FROM node:20 AS builder
2
2
 
3
3
  COPY ./ /src/node-red-contrib-processcube
4
4
 
@@ -5,12 +5,17 @@ services:
5
5
  context: .
6
6
  ports:
7
7
  - "1880:1880"
8
+ - "9229:9229"
8
9
  environment:
9
10
  - TZ=Europe/Berlin
10
11
  - ENGINE_URL=http://engine:8000
11
12
  - FLOWS=/nodered/node-red-contrib-processcube-flows.json
12
13
  volumes:
13
14
  - ./nodered/:/nodered/
15
+ - ./examples/:/examples/
16
+ depends_on:
17
+ - engine
18
+ - authority
14
19
 
15
20
  engine:
16
21
  image: 5minds/processcube_engine:2024-1
@@ -19,9 +24,16 @@ services:
19
24
  volumes:
20
25
  - ./processes:/processes:ro
21
26
  environment:
27
+ application__name: Engine for Node-RED contrib
22
28
  iam__baseUrl: http://authority:11560
23
29
  iam__allowAnonymousRootAccess: true
24
30
  command: --seed-dir=/processes --port 8000
31
+ depends_on:
32
+ - authority
33
+ healthcheck:
34
+ test: bash -c "[ -f /tmp/healthy ]"
35
+ timeout: 1s
36
+ retries: 20
25
37
 
26
38
  authority:
27
39
  image: 5minds/processcube_authority:3.0.4
@@ -0,0 +1,252 @@
1
+ [
2
+ {
3
+ "id": "a23d2e782beb66f4",
4
+ "type": "tab",
5
+ "label": "External Task Sample",
6
+ "disabled": false,
7
+ "info": "",
8
+ "env": []
9
+ },
10
+ {
11
+ "id": "70d7a70e375b162a",
12
+ "type": "group",
13
+ "z": "a23d2e782beb66f4",
14
+ "style": {
15
+ "stroke": "#999999",
16
+ "stroke-opacity": "1",
17
+ "fill": "none",
18
+ "fill-opacity": "1",
19
+ "label": true,
20
+ "label-position": "nw",
21
+ "color": "#a4a4a4"
22
+ },
23
+ "nodes": [
24
+ "2991a5e6df2b87d2",
25
+ "911fde53bcbb7e3f",
26
+ "d56bb7cd73fd220c",
27
+ "15a5f64b9e2e05fc"
28
+ ],
29
+ "x": 34,
30
+ "y": 79,
31
+ "w": 512,
32
+ "h": 142
33
+ },
34
+ {
35
+ "id": "31cb6729aac0ba46",
36
+ "type": "group",
37
+ "z": "a23d2e782beb66f4",
38
+ "style": {
39
+ "stroke": "#999999",
40
+ "stroke-opacity": "1",
41
+ "fill": "none",
42
+ "fill-opacity": "1",
43
+ "label": true,
44
+ "label-position": "nw",
45
+ "color": "#a4a4a4"
46
+ },
47
+ "nodes": [
48
+ "18e05d562d48f32d",
49
+ "49aee03a7885fae8",
50
+ "e4555d9019cd3f47",
51
+ "bd68c4bdc53b8f80",
52
+ "fb87f79852b22e4a",
53
+ "1ba1e62c9935255f",
54
+ "b49f226ba865e164"
55
+ ],
56
+ "x": 34,
57
+ "y": 259,
58
+ "w": 812,
59
+ "h": 202
60
+ },
61
+ {
62
+ "id": "2991a5e6df2b87d2",
63
+ "type": "externaltask-input",
64
+ "z": "a23d2e782beb66f4",
65
+ "g": "70d7a70e375b162a",
66
+ "name": "Test",
67
+ "engine": "42e6796dddd9d4db",
68
+ "topic": "Test",
69
+ "x": 110,
70
+ "y": 180,
71
+ "wires": [
72
+ [
73
+ "d56bb7cd73fd220c"
74
+ ]
75
+ ]
76
+ },
77
+ {
78
+ "id": "911fde53bcbb7e3f",
79
+ "type": "externaltask-output",
80
+ "z": "a23d2e782beb66f4",
81
+ "g": "70d7a70e375b162a",
82
+ "name": "Test Ende",
83
+ "x": 460,
84
+ "y": 180,
85
+ "wires": []
86
+ },
87
+ {
88
+ "id": "d56bb7cd73fd220c",
89
+ "type": "delay",
90
+ "z": "a23d2e782beb66f4",
91
+ "g": "70d7a70e375b162a",
92
+ "name": "",
93
+ "pauseType": "delay",
94
+ "timeout": "1",
95
+ "timeoutUnits": "seconds",
96
+ "rate": "1",
97
+ "nbRateUnits": "1",
98
+ "rateUnits": "second",
99
+ "randomFirst": "1",
100
+ "randomLast": "5",
101
+ "randomUnits": "seconds",
102
+ "drop": false,
103
+ "allowrate": false,
104
+ "outputs": 1,
105
+ "x": 280,
106
+ "y": 180,
107
+ "wires": [
108
+ [
109
+ "911fde53bcbb7e3f"
110
+ ]
111
+ ]
112
+ },
113
+ {
114
+ "id": "18e05d562d48f32d",
115
+ "type": "externaltask-input",
116
+ "z": "a23d2e782beb66f4",
117
+ "g": "31cb6729aac0ba46",
118
+ "name": "SampleError",
119
+ "engine": "42e6796dddd9d4db",
120
+ "topic": "SampleError",
121
+ "x": 130,
122
+ "y": 360,
123
+ "wires": [
124
+ [
125
+ "49aee03a7885fae8"
126
+ ]
127
+ ]
128
+ },
129
+ {
130
+ "id": "49aee03a7885fae8",
131
+ "type": "delay",
132
+ "z": "a23d2e782beb66f4",
133
+ "g": "31cb6729aac0ba46",
134
+ "name": "",
135
+ "pauseType": "delay",
136
+ "timeout": "5",
137
+ "timeoutUnits": "seconds",
138
+ "rate": "1",
139
+ "nbRateUnits": "1",
140
+ "rateUnits": "second",
141
+ "randomFirst": "1",
142
+ "randomLast": "5",
143
+ "randomUnits": "seconds",
144
+ "drop": false,
145
+ "allowrate": false,
146
+ "outputs": 1,
147
+ "x": 320,
148
+ "y": 360,
149
+ "wires": [
150
+ [
151
+ "bd68c4bdc53b8f80"
152
+ ]
153
+ ]
154
+ },
155
+ {
156
+ "id": "e4555d9019cd3f47",
157
+ "type": "catch",
158
+ "z": "a23d2e782beb66f4",
159
+ "g": "31cb6729aac0ba46",
160
+ "name": "",
161
+ "scope": "group",
162
+ "uncaught": false,
163
+ "x": 510,
164
+ "y": 420,
165
+ "wires": [
166
+ [
167
+ "fb87f79852b22e4a"
168
+ ]
169
+ ]
170
+ },
171
+ {
172
+ "id": "bd68c4bdc53b8f80",
173
+ "type": "function",
174
+ "z": "a23d2e782beb66f4",
175
+ "g": "31cb6729aac0ba46",
176
+ "name": "raise Error",
177
+ "func": "throw Error(\"hello error\");\n\nreturn msg;",
178
+ "outputs": 1,
179
+ "timeout": 0,
180
+ "noerr": 0,
181
+ "initialize": "",
182
+ "finalize": "",
183
+ "libs": [],
184
+ "x": 510,
185
+ "y": 360,
186
+ "wires": [
187
+ [
188
+ "1ba1e62c9935255f"
189
+ ]
190
+ ]
191
+ },
192
+ {
193
+ "id": "fb87f79852b22e4a",
194
+ "type": "externaltask-error",
195
+ "z": "a23d2e782beb66f4",
196
+ "g": "31cb6729aac0ba46",
197
+ "name": "Send Error to Engine",
198
+ "error": "MyErrorCode",
199
+ "x": 720,
200
+ "y": 420,
201
+ "wires": [
202
+ []
203
+ ]
204
+ },
205
+ {
206
+ "id": "1ba1e62c9935255f",
207
+ "type": "externaltask-output",
208
+ "z": "a23d2e782beb66f4",
209
+ "g": "31cb6729aac0ba46",
210
+ "name": "",
211
+ "x": 710,
212
+ "y": 360,
213
+ "wires": []
214
+ },
215
+ {
216
+ "id": "15a5f64b9e2e05fc",
217
+ "type": "comment",
218
+ "z": "a23d2e782beb66f4",
219
+ "g": "70d7a70e375b162a",
220
+ "name": "Simple External Task handling",
221
+ "info": "",
222
+ "x": 180,
223
+ "y": 120,
224
+ "wires": []
225
+ },
226
+ {
227
+ "id": "b49f226ba865e164",
228
+ "type": "comment",
229
+ "z": "a23d2e782beb66f4",
230
+ "g": "31cb6729aac0ba46",
231
+ "name": "Error handling with external tasks",
232
+ "info": "",
233
+ "x": 190,
234
+ "y": 300,
235
+ "wires": []
236
+ },
237
+ {
238
+ "id": "799125e21de02f13",
239
+ "type": "comment",
240
+ "z": "a23d2e782beb66f4",
241
+ "name": "For Testing, deploy \"External-Task-Sample.bpmn\" and start the process.",
242
+ "info": "",
243
+ "x": 300,
244
+ "y": 40,
245
+ "wires": []
246
+ },
247
+ {
248
+ "id": "42e6796dddd9d4db",
249
+ "type": "processcube-engine-config",
250
+ "url": "http://engine:8000"
251
+ }
252
+ ]
@@ -26,6 +26,20 @@
26
26
  </div>
27
27
  </script>
28
28
 
29
- <script type="text/html" data-help-name="externaltask-error">
30
- <p>A node which error response to an External Task of https://processcube.io</p>
29
+ <script type="text/markdown" data-help-name="externaltask-error">
30
+ Used for reporting errors in the processing of external tasks. The error
31
+ code `Error` in the configuration is forwarded to the ProcessCube engine for
32
+ handling within *Error-Boundary-Events*.
33
+
34
+ ## Inputs
35
+
36
+ : msg (Object) : Passed as `ErrorDetails` to the engine
37
+ : Error (string) : From the configuration
38
+ : Message (string) : The caught exception message
39
+ : StackTrace (string) : The stack trace of the exception
40
+
41
+ ### References
42
+
43
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
44
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
31
45
  </script>
@@ -8,24 +8,22 @@ 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
- let error = msg.error;
13
+ let msgError = msg.error;
14
14
 
15
- if (error === undefined) {
16
- error.message = "An error occurred";
17
- error.source = msg.payload;
15
+ if (msgError === undefined) {
16
+ msgError.message = "An error occurred";
18
17
  }
19
18
 
20
- msg.payload = {
21
- "error": {
22
- errorCode: config.error,
23
- errorMessage: error.message,
24
- errorDetails: error.source
25
- }
26
- };
19
+ const error = new Error(msgError.message);
20
+ error.errorCode = config.error;
21
+ error.errorDetails = RED.util.encodeObject(msg);
27
22
 
28
- eventEmitter.emit(`error-${externalTaskId}`, msg.payload);
23
+ msg.errorCode = config.error;
24
+ msg.errorMessage = msgError.message;
25
+
26
+ eventEmitter.emit(`handle-${flowNodeInstanceId}`, error, true);
29
27
 
30
28
  node.send(msg);
31
29
  });
@@ -31,6 +31,23 @@
31
31
  </div>
32
32
  </script>
33
33
 
34
- <script type="text/html" data-help-name="externaltask-input">
35
- <p>A node which subscribes to an External Task Topic of https://processcube.io</p>
34
+ <script type="text/markdown" data-help-name="externaltask-input">
35
+ Waiting for external tasks that correspond to the `Topic` configured in
36
+ the connected ProcessCube Engine for processing.
37
+
38
+ ## Outputs
39
+
40
+ : payload (string) : Defines the input of the external task token
41
+ : task (object) : The external task object
42
+ : flowNodeInstanceId : The Id of the external task, which is needed to complete the task
43
+
44
+ ### Details
45
+
46
+ - To finish the external task the `externaltask-output` node is required.
47
+ - For handling a error while executing a flow as external task the `externaltask-error` node is required.
48
+
49
+ ### References
50
+
51
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; Plattform
52
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED Integration in ProcessCube&copy;
36
53
  </script>
@@ -1,44 +1,24 @@
1
- const process = require('process');
2
1
  const EventEmitter = require('node:events');
3
2
 
4
- const engine_client = require('@5minds/processcube_engine_client');
5
-
6
3
  function showStatus(node, msgCounter) {
7
4
  if (msgCounter >= 1) {
8
- node.status({fill: "blue", shape: "dot", text: `handling tasks ${msgCounter}`});
5
+ node.status({fill: "blue", shape: "dot", text: `handling tasks ${msgCounter}.`});
9
6
  } else {
10
- node.status({fill: "blue", shape: "ring", text: `subcribed ${msgCounter}`});
7
+ node.status({fill: "blue", shape: "ring", text: `subcribed.`});
11
8
  }
12
9
  }
13
10
 
14
- function decrCounter(msgCounter) {
15
- msgCounter--;
16
-
17
- if (msgCounter < 0) {
18
- msgCounter = 0;
19
- }
20
-
21
- return msgCounter;
22
- }
11
+ const started_external_tasks = {};
23
12
 
24
13
  module.exports = function(RED) {
25
14
  function ExternalTaskInput(config) {
26
15
  RED.nodes.createNode(this,config);
27
16
  var node = this;
28
- var msgCounter = 0;
29
17
  var flowContext = node.context().flow;
30
- var nodeContext = node.context();
31
-
18
+
32
19
  this.engine = this.server = RED.nodes.getNode(config.engine);
33
20
 
34
- const engineUrl = this.engine?.url || process.env.ENGINE_URL || 'http://engine:8000';
35
-
36
- var client = nodeContext.get('client');
37
-
38
- if (!client) {
39
- nodeContext.set('client', new engine_client.EngineClient(engineUrl));
40
- client = nodeContext.get('client');
41
- }
21
+ const client = this.engine.getEngineClient();
42
22
 
43
23
  var eventEmitter = flowContext.get('emitter');
44
24
 
@@ -50,30 +30,75 @@ module.exports = function(RED) {
50
30
  client.externalTasks.subscribeToExternalTaskTopic(
51
31
  config.topic,
52
32
  async (payload, externalTask) => {
53
- msgCounter++;
54
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
+ };
41
+
55
42
  return await new Promise((resolve, reject) => {
56
-
57
- // TODO: once ist 2x gebunden
58
- eventEmitter.once(`finish-${externalTask.flowNodeInstanceId}`, (result) => {
59
- msgCounter = decrCounter(msgCounter);
60
43
 
61
- showStatus(node, msgCounter);
62
- resolve(result);
63
- });
44
+ const handleFinishTask = (msg) => {
45
+ let result = RED.util.encodeObject(msg.payload);
46
+
47
+ node.log(`handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* ${externalTask.processInstanceId} with result ${result} on msg._msgid ${msg._msgid}.`);
48
+
49
+ if (externalTask.flowNodeInstanceId) {
50
+ delete started_external_tasks[externalTask.flowNodeInstanceId];
51
+ }
52
+
53
+ showStatus(node, Object.keys(started_external_tasks).length);
54
+
64
55
 
65
- eventEmitter.once(`error-${externalTask.flowNodeInstanceId}`, (msg) => {
66
- msgCounter = decrCounter(msgCounter);
67
- showStatus(node, msgCounter);
56
+ //resolve(result);
57
+ saveHandleCallback(result, resolve)
58
+ };
68
59
 
69
- var result = msg.payload ? msg.payload : msg;
60
+ const handleErrorTask = (msg) => {
70
61
 
71
- reject(result);
62
+ node.log(`handle error event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' on *msg._msgid* '${msg._msgid}'.`);
63
+
64
+ if (externalTask.flowNodeInstanceId) {
65
+ delete started_external_tasks[externalTask.flowNodeInstanceId];
66
+ }
67
+
68
+ showStatus(node, Object.keys(started_external_tasks).length);
69
+
70
+
71
+ // TODO: with reject, the default error handling is proceed
72
+ // SEE: https://github.com/5minds/ProcessCube.Engine.Client.ts/blob/develop/src/ExternalTaskWorker.ts#L180
73
+ // reject(result);
74
+ //resolve(msg);
75
+ saveHandleCallback(msg, resolve);
76
+ };
77
+
78
+ eventEmitter.once(`handle-${externalTask.flowNodeInstanceId}`, (msg, isError = false) => {
79
+ node.log(`handle event for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}' and *isError* '${isError}'`);
80
+
81
+ if (isError) {
82
+ handleErrorTask(msg);
83
+ } else {
84
+ handleFinishTask(msg);
85
+ }
72
86
  });
73
87
 
74
- showStatus(node, msgCounter);
88
+ started_external_tasks[externalTask.flowNodeInstanceId] = externalTask;
89
+
90
+ showStatus(node, Object.keys(started_external_tasks).length);
91
+
92
+ let msg = {
93
+ _msgid: RED.util.generateId(),
94
+ task: RED.util.encodeObject(externalTask),
95
+ payload: payload,
96
+ flowNodeInstanceId: externalTask.flowNodeInstanceId
97
+ };
75
98
 
76
- node.send({topic: externalTask.topic, payload: payload, externalTaskId: externalTask.flowNodeInstanceId});
99
+ node.log(`Received *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}' with *msg._msgid* '${msg._msgid}'`);
100
+
101
+ node.send(msg);
77
102
  });
78
103
  },
79
104
  ).then(async externalTaskWorker => {
@@ -83,17 +108,45 @@ module.exports = function(RED) {
83
108
  node.server.registerOnIdentityChanged((identity) => {
84
109
  externalTaskWorker.identity = identity;
85
110
  });
86
- await externalTaskWorker.start();
87
111
 
88
- node.on("close", async () => {
112
+ // export type WorkerErrorHandler = (errorType: 'fetchAndLock' | 'extendLock' | 'processExternalTask' | 'finishExternalTask', error: Error, externalTask?: ExternalTask<any>) => void;
113
+ externalTaskWorker.onWorkerError((errorType, error, externalTask) => {
114
+ switch (errorType) {
115
+ case 'extendLock':
116
+ case 'finishExternalTask':
117
+ case 'processExternalTask':
118
+ node.error(`Worker error ${errorType} for *external task flowNodeInstanceId* '${externalTask.flowNodeInstanceId}' and *processInstanceId* '${externalTask.processInstanceId}': ${error.message}`);
119
+
120
+ if (externalTask) {
121
+ delete started_external_tasks[externalTask.flowNodeInstanceId];
122
+ }
123
+
124
+ showStatus(node, Object.keys(started_external_tasks).length);
125
+ break;
126
+ default:
127
+ node.error(`Worker error ${errorType}: ${error.message}`);
128
+ break;
129
+ }
130
+ });
131
+
132
+ try {
133
+ externalTaskWorker.start();
134
+ } catch (error) {
135
+ node.error(`Worker start 'externalTaskWorker.start' failed: ${error.message}`);
136
+ }
137
+
138
+ node.on("close", () => {
89
139
  try {
90
140
  externalTaskWorker.stop();
91
141
  } catch {
92
- console.warn('Client close failed');
142
+ node.error('Client close failed');
93
143
  }
94
144
  });
95
145
  }
96
- );
146
+ ).catch((error) => {
147
+ node.error(`Error in subscribeToExternalTaskTopic: ${error.message}`);
148
+ });
97
149
  }
150
+
98
151
  RED.nodes.registerType("externaltask-input", ExternalTaskInput);
99
152
  }
@@ -21,6 +21,16 @@
21
21
  </div>
22
22
  </script>
23
23
 
24
- <script type="text/html" data-help-name="externaltask-output">
25
- <p>A node which response to an External Task of https://processcube.io</p>
24
+ <script type="text/markdown" data-help-name="externaltask-output">
25
+ Used to complete the external task. The `msg.payload` is returned to the ProcessCube
26
+ engine as the result of the external task.
27
+
28
+ ## Inputs
29
+
30
+ : payload (Object) : Returned to the ProcessCube engine as the result of the external task
31
+
32
+ ### References
33
+
34
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
35
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
26
36
  </script>
@@ -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(`finish-${externalTaskId}`, msg.payload);
17
+ eventEmitter.emit(`handle-${flowNodeInstanceId}`, msg, false);
18
18
  });
19
19
  }
20
20
  RED.nodes.registerType("externaltask-output", ExternalTaskOutput);