Skip to content

Commit

Permalink
Add new version; remove eventaggreatore use eventemitter
Browse files Browse the repository at this point in the history
  • Loading branch information
moellenbeck committed Apr 25, 2024
1 parent a502fd3 commit 71a1e8c
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .node-red/data/.config.nodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
},
"@5minds/node-red-contrib-processcube": {
"name": "@5minds/node-red-contrib-processcube",
"version": "0.0.8",
"version": "0.0.9",
"local": true,
"user": false,
"nodes": {
Expand Down
13 changes: 12 additions & 1 deletion .node-red/data/.config.nodes.json.backup
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
},
"@5minds/node-red-contrib-processcube": {
"name": "@5minds/node-red-contrib-processcube",
"version": "0.0.6",
"version": "0.0.8",
"local": true,
"user": false,
"nodes": {
Expand All @@ -525,6 +525,17 @@
"module": "@5minds/node-red-contrib-processcube",
"file": "/data/node_modules/node-red-contrib-processcube/externaltask-output.js"
},
"externaltaskError": {
"name": "externaltaskError",
"types": [
"externaltask-error"
],
"enabled": true,
"local": true,
"user": false,
"module": "@5minds/node-red-contrib-processcube",
"file": "/data/node_modules/node-red-contrib-processcube/externaltask-error.js"
},
"processStart": {
"name": "processStart",
"types": [
Expand Down
3 changes: 2 additions & 1 deletion .node-red/data/flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"type": "externaltask-input",
"z": "a23d2e782beb66f4",
"name": "processmodels",
"engine": "",
"topic": "processmodels",
"x": 100,
"y": 460,
Expand Down Expand Up @@ -725,7 +726,7 @@
"statusVal": "",
"statusType": "auto",
"x": 380,
"y": 200,
"y": 220,
"wires": []
},
{
Expand Down
25 changes: 0 additions & 25 deletions EventAggregator.js

This file was deleted.

7 changes: 4 additions & 3 deletions externaltask-error.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const EventAggregator = require('./EventAggregator');

module.exports = function(RED) {
function ExternalTaskError(config) {
RED.nodes.createNode(this,config);
var node = this;

var flowContext = node.context().flow;
var eventEmitter = flowContext.get('emitter');

node.on('input', function(msg) {

const externalTaskId = msg.externalTaskId;
Expand All @@ -17,7 +18,7 @@ module.exports = function(RED) {
}
};

EventAggregator.eventEmitter.emit(`error-${externalTaskId}`, msg.payload);
eventEmitter.emit(`error-${externalTaskId}`, msg.payload);
});
}
RED.nodes.registerType("externaltask-error", ExternalTaskError);
Expand Down
9 changes: 7 additions & 2 deletions externaltask-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
category: 'ProcessCube',
color: '#00aed7',
defaults: {
name: {value:""},
topic: {value:""}
name: {value: ""},
engine: {value: "http://engine:8000"},
topic: {value: ""}
},
inputs: 0,
outputs: 1,
Expand All @@ -20,6 +21,10 @@
<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-engine"><i class="fa fa-tag"></i> Engine-URL</label>
<input type="text" id="node-input-engine" placeholder="http://engine:8000">
</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">
Expand Down
19 changes: 12 additions & 7 deletions externaltask-input.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const process = require('process');
const EventEmitter = require('node:events');

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) {
Expand All @@ -20,6 +16,14 @@ module.exports = function(RED) {
RED.nodes.createNode(this,config);
var node = this;
var msgCounter = 0;
var flowContext = node.context().flow;

const engineUrl = config.engine || process.env.ENGINE_URL || 'http://engine:8000';

const client = new engine_client.EngineClient(engineUrl);

flowContext.set('emitter', new EventEmitter());
var eventEmitter = flowContext.get('emitter');

client.externalTasks.subscribeToExternalTaskTopic(
config.topic,
Expand All @@ -28,13 +32,14 @@ module.exports = function(RED) {

return await new Promise((resolve, reject) => {

EventAggregator.eventEmitter.once(`finish-${externalTask.flowNodeInstanceId}`, (result) => {
// TODO: once ist 2x gebunden
eventEmitter.once(`finish-${externalTask.flowNodeInstanceId}`, (result) => {
msgCounter--;
showStatus(node, msgCounter);
resolve(result);
});

EventAggregator.eventEmitter.once(`error-${externalTask.flowNodeInstanceId}`, (msg) => {
eventEmitter.once(`error-${externalTask.flowNodeInstanceId}`, (msg) => {
msgCounter--;
showStatus(node, msgCounter);

Expand Down
7 changes: 4 additions & 3 deletions externaltask-output.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const EventAggregator = require('./EventAggregator');

module.exports = function(RED) {
function ExternalTaskOutput(config) {
RED.nodes.createNode(this,config);
var node = this;

var flowContext = node.context().flow;
var eventEmitter = flowContext.get('emitter');

node.on('input', function(msg) {

const externalTaskId = msg.externalTaskId;

EventAggregator.eventEmitter.emit(`finish-${externalTaskId}`, msg.payload);
eventEmitter.emit(`finish-${externalTaskId}`, msg.payload);
});
}
RED.nodes.registerType("externaltask-output", ExternalTaskOutput);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@5minds/node-red-contrib-processcube",
"version": "0.0.8",
"version": "0.0.9",
"license": "MIT",
"description": "Node-RED nodes for ProcessCube",
"keywords": [
Expand Down

0 comments on commit 71a1e8c

Please sign in to comment.