Skip to content

Commit

Permalink
Add error handling to nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
moellenbeck committed Nov 14, 2024
1 parent 5e0b5a4 commit 08b6df8
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 17 deletions.
11 changes: 9 additions & 2 deletions endevent-finished-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module.exports = function (RED) {
});
},
{ identity: currentIdentity },
);
).catch((error) => {
node.error(error);
});

node.engine.registerOnIdentityChanged(async (identity) => {
client.events.removeSubscription(subscription, currentIdentity);
Expand All @@ -34,7 +36,12 @@ module.exports = function (RED) {
});
},
{ identity: currentIdentity },
);
).catch((error) => {
node.error(error);
});

}).catch((error) => {
node.error(error);
});

node.on('close', async () => {
Expand Down
11 changes: 11 additions & 0 deletions nodered/flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,17 @@
"name": "Engine Auth 8000",
"url": "http://engine:8000"
},
{
"id": "392373f3e1403770",
"type": "processcube-engine-config",
"name": "",
"url": "http://host.docker.internal:56000",
"urlType": "str",
"clientId": "",
"clientIdType": "str",
"clientSecret": "",
"clientSecretType": "str"
},
{
"id": "2991a5e6df2b87d2",
"type": "externaltask-input",
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": "1.5.4",
"version": "1.5.5",
"license": "MIT",
"description": "Node-RED nodes for ProcessCube",
"scripts": {
Expand Down
63 changes: 51 additions & 12 deletions process-event-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'started':
return await client.notification.onProcessStarted(
async (processNotification) => {
Expand All @@ -70,6 +72,8 @@ module.exports = function (RED) {

const matchingInstances = await client.processInstances.query(newQuery, {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});

if (
Expand All @@ -91,7 +95,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'resumed':
return await client.notification.onProcessResumed(
async (processNotification) => {
Expand All @@ -108,6 +114,8 @@ module.exports = function (RED) {

const matchingInstances = await client.processInstances.query(newQuery, {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});

if (
Expand All @@ -128,7 +136,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'finished':
return await client.notification.onProcessEnded(
async (processNotification) => {
Expand All @@ -145,6 +155,8 @@ module.exports = function (RED) {

const matchingInstances = await client.processInstances.query(newQuery, {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});

if (
Expand All @@ -166,7 +178,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'terminated':
return await client.notification.onProcessTerminated(
async (processNotification) => {
Expand All @@ -183,6 +197,8 @@ module.exports = function (RED) {

const matchingInstances = await client.processInstances.query(newQuery, {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});

if (
Expand All @@ -203,7 +219,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'error':
return await client.notification.onProcessError(
async (processNotification) => {
Expand All @@ -220,6 +238,8 @@ module.exports = function (RED) {

const matchingInstances = await client.processInstances.query(newQuery, {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});

if (
Expand All @@ -240,7 +260,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'owner-changed':
return await client.notification.onProcessOwnerChanged(
async (processNotification) => {
Expand All @@ -257,6 +279,8 @@ module.exports = function (RED) {

const matchingInstances = await client.processInstances.query(newQuery, {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});

if (
Expand All @@ -276,7 +300,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'instances-deleted':
return await client.notification.onProcessInstancesDeleted(
async (processNotification) => {
Expand All @@ -293,6 +319,8 @@ module.exports = function (RED) {

const matchingInstances = await client.processInstances.query(newQuery, {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});

if (
Expand All @@ -312,7 +340,9 @@ module.exports = function (RED) {
}
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'is-executable-changed':
return await client.notification.onProcessIsExecutableChanged(
(processNotification) => {
Expand All @@ -330,7 +360,9 @@ module.exports = function (RED) {
});
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'deployed':
return await client.notification.onProcessDeployed(
(processNotification) => {
Expand All @@ -348,7 +380,9 @@ module.exports = function (RED) {
});
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
case 'undeployed':
return await client.notification.onProcessUndeployed(
(processNotification) => {
Expand All @@ -366,7 +400,9 @@ module.exports = function (RED) {
});
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});
default:
console.error('no such event: ' + eventType);
break;
Expand Down Expand Up @@ -399,7 +435,10 @@ module.exports = function (RED) {
});
},
{ identity: currentIdentity }
);
).catch((error) => {
node.error(error);
});

});

node.on('close', () => {
Expand Down
5 changes: 4 additions & 1 deletion processdefinition-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ module.exports = function (RED) {

query = {
...query,
identity: engine.identity,
identity: undefined,
};

node.log(`Querying process definitions with query: ${JSON.stringify(query)}`);
client.processDefinitions.getAll(query).then((matchingProcessDefinitions) => {

if (config.models_only && matchingProcessDefinitions.totalCount > 0) {
Expand All @@ -40,6 +41,8 @@ module.exports = function (RED) {
}

node.send(msg);
}).catch((error) => {
node.error(error);
});
});
}
Expand Down
10 changes: 9 additions & 1 deletion usertask-event-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@ module.exports = function (RED) {
case 'new':
return await client.userTasks.onUserTaskWaiting(userTaskCallback(), {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});
case 'finished':
return await client.userTasks.onUserTaskFinished(userTaskCallback(), {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});
case 'reserved':
return await client.userTasks.onUserTaskReserved(userTaskCallback(), {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});
case 'reservation-canceled':
return await client.userTasks.onUserTaskReservationCanceled(userTaskCallback(), {
identity: currentIdentity,
}).catch((error) => {
node.error(error);
});
default:
console.error('no such event: ' + config.eventtype);
Expand All @@ -79,7 +87,7 @@ module.exports = function (RED) {
currentIdentity = identity;

subscription = subscribe();
});
})

node.on('close', async () => {
if (node.engine && node.engine.engineClient && client) {
Expand Down

0 comments on commit 08b6df8

Please sign in to comment.