@5minds/node-red-contrib-processcube 1.2.3-feature-241db2-m21w1ewd → 1.3.0-feature-92414d-m21x3yqt
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/package.json +1 -1
- package/wait-for-usertask.html +2 -1
- package/wait-for-usertask.js +57 -59
package/package.json
CHANGED
package/wait-for-usertask.html
CHANGED
@@ -72,5 +72,6 @@ Waiting for Usertasks of the connected ProcessCube Engine.
|
|
72
72
|
|
73
73
|
### References
|
74
74
|
|
75
|
-
|
75
|
+
- [The ProcessCube© Developer Network](https://processcube.io) - All documentation for the ProcessCube© platform
|
76
|
+
- [ProcessCube© LowCode Integration](https://processcube.io/docs/node-red) - LowCode integration in ProcessCube©
|
76
77
|
</script>
|
package/wait-for-usertask.js
CHANGED
@@ -1,91 +1,89 @@
|
|
1
|
-
const process = require('process');
|
2
|
-
|
3
|
-
const engine_client = require('@5minds/processcube_engine_client');
|
4
|
-
const { userInfo } = require('os');
|
5
|
-
|
6
1
|
module.exports = function (RED) {
|
7
2
|
function WaitForUsertask(config) {
|
8
3
|
RED.nodes.createNode(this, config);
|
9
4
|
var node = this;
|
10
|
-
var nodeContext = node.context();
|
11
|
-
|
12
|
-
this.engine = this.server = RED.nodes.getNode(config.engine);
|
13
|
-
|
14
|
-
const engineUrl = this.engine?.url || process.env.ENGINE_URL || 'http://engine:8000';
|
15
5
|
|
16
|
-
|
6
|
+
const engine = RED.nodes.getNode(config.engine);
|
17
7
|
|
18
|
-
|
19
|
-
nodeContext.set('client', new engine_client.EngineClient(engineUrl));
|
20
|
-
client = nodeContext.get('client');
|
21
|
-
}
|
8
|
+
const client = engine.engineClient;
|
22
9
|
|
23
|
-
|
24
|
-
let currentIdentity = null;
|
25
10
|
let subscription = null;
|
11
|
+
let currentIdentity = engine.identity;
|
12
|
+
let subscribe = null;
|
26
13
|
|
27
14
|
node.on('input', async function (msg) {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
15
|
+
subscribe = async () => {
|
16
|
+
if (!client) {
|
17
|
+
node.error('No engine configured.');
|
18
|
+
return;
|
19
|
+
}
|
34
20
|
|
35
|
-
|
21
|
+
const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
|
36
22
|
|
37
|
-
|
23
|
+
subscription = await client.userTasks.onUserTaskWaiting(async (userTaskWaitingNotification) => {
|
38
24
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
const newQuery = {
|
26
|
+
'flowNodeInstanceId': userTaskWaitingNotification.flowNodeInstanceId,
|
27
|
+
...query
|
28
|
+
};
|
43
29
|
|
44
|
-
|
30
|
+
const matchingFlowNodes = await client.userTasks.query(newQuery, { identity: currentIdentity });
|
45
31
|
|
46
|
-
|
47
|
-
|
32
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
|
33
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
48
34
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
35
|
+
msg.payload = { userTask: userTask };
|
36
|
+
node.send(msg);
|
37
|
+
} else {
|
38
|
+
// nothing todo - wait for next notification
|
39
|
+
}
|
54
40
|
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
// remove subscription
|
42
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
43
|
+
}, { identity: currentIdentity });
|
58
44
|
|
59
|
-
|
45
|
+
node.log({"Handling old userTasks config.only_for_new": config.only_for_new});
|
60
46
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
47
|
+
if (config.only_for_new === false) {
|
48
|
+
// only check suspended user tasks
|
49
|
+
const suspendedQuery = {
|
50
|
+
'state': 'suspended',
|
51
|
+
...query
|
52
|
+
};
|
67
53
|
|
68
|
-
|
54
|
+
const matchingFlowNodes = await client.userTasks.query(suspendedQuery, { identity: currentIdentity });
|
69
55
|
|
70
|
-
|
71
|
-
|
56
|
+
if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length >= 1) {
|
57
|
+
const userTask = matchingFlowNodes.userTasks[0];
|
72
58
|
|
73
|
-
|
74
|
-
|
59
|
+
msg.payload = { userTask: userTask };
|
60
|
+
node.send(msg);
|
75
61
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
62
|
+
// remove subscription
|
63
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
64
|
+
} else {
|
65
|
+
// let the *currentIdentity* be active
|
66
|
+
}
|
80
67
|
}
|
68
|
+
};
|
69
|
+
|
70
|
+
subscribe();
|
71
|
+
});
|
72
|
+
|
73
|
+
node.engine.registerOnIdentityChanged(async (identity) => {
|
74
|
+
|
75
|
+
if (subscription) {
|
76
|
+
client.userTasks.removeSubscription(subscription, currentIdentity);
|
77
|
+
currentIdentity = identity;
|
78
|
+
subscribe();
|
79
|
+
} else {
|
80
|
+
currentIdentity = identity;
|
81
81
|
}
|
82
82
|
});
|
83
83
|
|
84
84
|
node.on("close", async () => {
|
85
|
-
if (client != null) {
|
85
|
+
if (client != null && subscription != null) {
|
86
86
|
client.userTasks.removeSubscription(subscription, currentIdentity);
|
87
|
-
client.dispose();
|
88
|
-
client = null;
|
89
87
|
}
|
90
88
|
});
|
91
89
|
}
|