@5minds/node-red-contrib-processcube 0.14.0-develop-7fe136-lygsbbpi → 0.14.0-feature-bdf6dc-lyw1t0bw
Sign up to get free protection for your applications and to get access to all the features.
- package/externaltask-error.js +1 -1
- package/externaltask-input.js +57 -24
- package/externaltask-output.js +1 -1
- package/package.json +1 -1
package/externaltask-error.js
CHANGED
package/externaltask-input.js
CHANGED
@@ -11,24 +11,16 @@ function showStatus(node, msgCounter) {
|
|
11
11
|
}
|
12
12
|
}
|
13
13
|
|
14
|
-
|
15
|
-
msgCounter--;
|
16
|
-
|
17
|
-
if (msgCounter < 0) {
|
18
|
-
msgCounter = 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
return msgCounter;
|
22
|
-
}
|
14
|
+
const started_external_tasks = {};
|
23
15
|
|
24
16
|
module.exports = function(RED) {
|
25
17
|
function ExternalTaskInput(config) {
|
26
18
|
RED.nodes.createNode(this,config);
|
27
19
|
var node = this;
|
28
|
-
var msgCounter = 0;
|
29
20
|
var flowContext = node.context().flow;
|
30
21
|
var nodeContext = node.context();
|
31
22
|
|
23
|
+
|
32
24
|
this.engine = this.server = RED.nodes.getNode(config.engine);
|
33
25
|
|
34
26
|
const engineUrl = this.engine?.url || process.env.ENGINE_URL || 'http://engine:8000';
|
@@ -50,30 +42,57 @@ module.exports = function(RED) {
|
|
50
42
|
client.externalTasks.subscribeToExternalTaskTopic(
|
51
43
|
config.topic,
|
52
44
|
async (payload, externalTask) => {
|
53
|
-
|
54
|
-
|
45
|
+
|
55
46
|
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
47
|
|
61
|
-
|
48
|
+
const handleFinishTask = (msg) => {
|
49
|
+
if (msg.externalTaskId) {
|
50
|
+
delete started_external_tasks[msg.externalTaskId];
|
51
|
+
}
|
52
|
+
|
53
|
+
showStatus(node, len(started_external_tasks.keys()));
|
54
|
+
|
55
|
+
let result = RED.util.encodeObject(msg.payload);
|
56
|
+
|
62
57
|
resolve(result);
|
63
|
-
}
|
58
|
+
};
|
59
|
+
|
60
|
+
const handleErrorTask = (msg) => {
|
61
|
+
if (msg.externalTaskId) {
|
62
|
+
delete started_external_tasks[msg.externalTaskId];
|
63
|
+
}
|
64
64
|
|
65
|
-
|
66
|
-
msgCounter = decrCounter(msgCounter);
|
67
|
-
showStatus(node, msgCounter);
|
65
|
+
showStatus(node, len(started_external_tasks.keys()));
|
68
66
|
|
69
|
-
|
67
|
+
let result = RED.util.encodeObject(msg);
|
70
68
|
|
71
69
|
reject(result);
|
70
|
+
};
|
71
|
+
|
72
|
+
eventEmitter.once(`handle-${externalTask.flowNodeInstanceId}`, (msg, isError = false) => {
|
73
|
+
node.log(`handle event for external task ${externalTask.flowNodeInstanceId} and process it with msg._msgid ${msg._msgid} and isError ${isError}`);
|
74
|
+
|
75
|
+
if (isError) {
|
76
|
+
handleErrorTask(msg);
|
77
|
+
} else {
|
78
|
+
handleFinishTask(msg);
|
79
|
+
}
|
72
80
|
});
|
73
81
|
|
74
|
-
|
82
|
+
started_external_tasks[externalTask.flowNodeInstanceId] = externalTask;
|
83
|
+
|
84
|
+
showStatus(node, len(started_external_tasks.keys()));
|
85
|
+
|
86
|
+
let msg = {
|
87
|
+
_msgid: RED.util.generateId(),
|
88
|
+
topic: externalTask.topic,
|
89
|
+
payload: payload,
|
90
|
+
externalTaskId: externalTask.flowNodeInstanceId
|
91
|
+
};
|
92
|
+
|
93
|
+
node.log(`Received external task ${externalTask.flowNodeInstanceId} and process it with msg._msgid ${msg._msgid}`);
|
75
94
|
|
76
|
-
node.send(
|
95
|
+
node.send(msg);
|
77
96
|
});
|
78
97
|
},
|
79
98
|
).then(async externalTaskWorker => {
|
@@ -83,6 +102,19 @@ module.exports = function(RED) {
|
|
83
102
|
node.server.registerOnIdentityChanged((identity) => {
|
84
103
|
externalTaskWorker.identity = identity;
|
85
104
|
});
|
105
|
+
|
106
|
+
// export type WorkerErrorHandler = (errorType: 'fetchAndLock' | 'extendLock' | 'processExternalTask' | 'finishExternalTask', error: Error, externalTask?: ExternalTask<any>) => void;
|
107
|
+
externalTaskWorker.onWorkerError((errorType, error, externalTask) => {
|
108
|
+
node.error(`Worker error ${errorType} for external task ${externalTask.flowNodeInstanceId}: ${error.message}`);
|
109
|
+
externalTaskWorker.stop();
|
110
|
+
|
111
|
+
if (msg.externalTaskId) {
|
112
|
+
delete started_external_tasks[msg.externalTaskId];
|
113
|
+
}
|
114
|
+
|
115
|
+
showStatus(node, len(started_external_tasks.keys()));
|
116
|
+
});
|
117
|
+
|
86
118
|
await externalTaskWorker.start();
|
87
119
|
|
88
120
|
node.on("close", async () => {
|
@@ -95,5 +127,6 @@ module.exports = function(RED) {
|
|
95
127
|
}
|
96
128
|
);
|
97
129
|
}
|
130
|
+
|
98
131
|
RED.nodes.registerType("externaltask-input", ExternalTaskInput);
|
99
132
|
}
|
package/externaltask-output.js
CHANGED
@@ -14,7 +14,7 @@ module.exports = function(RED) {
|
|
14
14
|
node.error('Error: The message did not contain the required external task id.', msg);
|
15
15
|
}
|
16
16
|
|
17
|
-
eventEmitter.emit(`
|
17
|
+
eventEmitter.emit(`handle-${externalTask.flowNodeInstanceId}`, msg, false);
|
18
18
|
});
|
19
19
|
}
|
20
20
|
RED.nodes.registerType("externaltask-output", ExternalTaskOutput);
|