Skip to content

Commit

Permalink
Reorder files, remove subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
moellenbeck committed Apr 21, 2024
1 parent 1dbb82c commit 0e586ab
Show file tree
Hide file tree
Showing 9 changed files with 1,060 additions and 0 deletions.
25 changes: 25 additions & 0 deletions EventAggregator.js
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
}
31 changes: 31 additions & 0 deletions externaltask-input.html
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>
54 changes: 54 additions & 0 deletions externaltask-input.js
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);
}
26 changes: 26 additions & 0 deletions externaltask-output.html
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>
16 changes: 16 additions & 0 deletions externaltask-output.js
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);
}
Loading

0 comments on commit 0e586ab

Please sign in to comment.