-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dbb82c
commit 0e586ab
Showing
9 changed files
with
1,060 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const EventEmitter = require('node:events'); | ||
|
||
const eventEmitter = new EventEmitter(); | ||
|
||
const eventSubscriptionDictionary = {}; | ||
|
||
function subscribeOnce(eventName, callback) { | ||
eventSubscriptionDictionary[eventName] = callback; | ||
} | ||
|
||
async function publish(eventName, payload) { | ||
const callback = eventSubscriptionDictionary[eventName]; | ||
|
||
if (callback) { | ||
await callback(payload); | ||
delete eventSubscriptionDictionary[eventName] | ||
} | ||
} | ||
|
||
module.exports = { | ||
eventEmitter: eventEmitter, | ||
subscribeOnce: subscribeOnce, | ||
publish: publish, | ||
countSubscriptions: () => Object.keys(eventSubscriptionDictionary).length | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script type="text/javascript"> | ||
RED.nodes.registerType('externaltask-input',{ | ||
category: 'ProcessCube', | ||
color: '#00aed7', | ||
defaults: { | ||
name: {value:""}, | ||
topic: {value:""} | ||
}, | ||
inputs: 0, | ||
outputs: 1, | ||
icon: "font-awesome/fa-envelope-open", | ||
label: function() { | ||
return this.name||"externaltask-input"; | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/html" data-template-name="externaltask-input"> | ||
<div class="form-row"> | ||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> | ||
<input type="text" id="node-input-name" placeholder="Name"> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-topic"><i class="fa fa-tag"></i> Topic</label> | ||
<input type="text" id="node-input-topic" placeholder="Topic of ExternalTask"> | ||
</div> | ||
</script> | ||
|
||
<script type="text/html" data-help-name="externaltask-input"> | ||
<p>A node which subscribes to an External Task Topic of https://processcube.io</p> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const process = require('process'); | ||
|
||
const engine_client = require('@5minds/processcube_engine_client'); | ||
const EventAggregator = require('./EventAggregator'); | ||
|
||
const engineUrl = process.env.ENGINE_URL || 'http://engine:8000'; | ||
|
||
const client = new engine_client.EngineClient(engineUrl); | ||
|
||
function showStatus(node, msgCounter) { | ||
if (msgCounter >= 1) { | ||
node.status({fill: "blue", shape: "dot", text: `handling tasks ${msgCounter}`}); | ||
} else { | ||
node.status({fill: "blue", shape: "ring", text: `subcribed ${msgCounter}`}); | ||
} | ||
} | ||
|
||
module.exports = function(RED) { | ||
function ExternalTaskInput(config) { | ||
RED.nodes.createNode(this,config); | ||
var node = this; | ||
var msgCounter = 0; | ||
|
||
client.externalTasks.subscribeToExternalTaskTopic( | ||
config.topic, | ||
async (payload, externalTask) => { | ||
msgCounter++; | ||
|
||
return await new Promise((resolve, reject) => { | ||
|
||
EventAggregator.eventEmitter.once(`finish-${externalTask.flowNodeInstanceId}`, (result) => { | ||
msgCounter--; | ||
showStatus(node, msgCounter); | ||
resolve(result); | ||
}); | ||
|
||
EventAggregator.eventEmitter.once(`error-${externalTask.flowNodeInstanceId}`, (result) => { | ||
msgCounter--; | ||
showStatus(node, msgCounter); | ||
reject(result); | ||
}); | ||
|
||
showStatus(node, msgCounter); | ||
node.send({ topic: externalTask.topic, externalTaskId: externalTask.flowNodeInstanceId, payload: payload}); | ||
}); | ||
}, | ||
).then(externalTaskWorker => { | ||
node.status({fill: "blue", shape: "ring", text: "subcribed"}); | ||
externalTaskWorker.start(); | ||
} | ||
); | ||
} | ||
RED.nodes.registerType("externaltask-input", ExternalTaskInput); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script type="text/javascript"> | ||
RED.nodes.registerType('externaltask-output',{ | ||
category: 'ProcessCube', | ||
color: '#00aed7', | ||
defaults: { | ||
name: {value:""} | ||
}, | ||
inputs: 1, | ||
outputs: 0, | ||
icon: "font-awesome/fa-envelope", | ||
label: function() { | ||
return this.name||"externaltask-output"; | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/html" data-template-name="externaltask-output"> | ||
<div class="form-row"> | ||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> | ||
<input type="text" id="node-input-name" placeholder="Name"> | ||
</div> | ||
</script> | ||
|
||
<script type="text/html" data-help-name="externaltask-output"> | ||
<p>A node which response to an External Task of https://processcube.io</p> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const EventAggregator = require('./EventAggregator'); | ||
|
||
module.exports = function(RED) { | ||
function ExternalTaskOutput(config) { | ||
RED.nodes.createNode(this,config); | ||
var node = this; | ||
|
||
node.on('input', function(msg) { | ||
|
||
const externalTaskId = msg.externalTaskId; | ||
|
||
EventAggregator.eventEmitter.emit(`finish-${externalTaskId}`, msg.payload); | ||
}); | ||
} | ||
RED.nodes.registerType("externaltask-output", ExternalTaskOutput); | ||
} |
Oops, something went wrong.