Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@5minds/node-red-contrib-processcube

Package Overview
Dependencies
Maintainers
0
Versions
358
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@5minds/node-red-contrib-processcube - npm Package Compare versions

Comparing version 1.6.0-develop-624ecd-m4somph0 to 1.6.0-process-instance-delete-hotfix-4a60e6-m4vbfe4n

2

package.json
{
"name": "@5minds/node-red-contrib-processcube",
"version": "1.6.0-develop-624ecd-m4somph0",
"version": "1.6.0-process-instance-delete-hotfix-4a60e6-m4vbfe4n",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Node-RED nodes for ProcessCube",

module.exports = function (RED) {
function ProcessInstanceDelete(config) {
RED.nodes.createNode(this, config);
var node = this;
const node = this;
node.on('input', async function (msg) {
node.engine = RED.nodes.getNode(config.engine);
const client = node.engine.engineClient;
const client = node.engine ? node.engine.engineClient : null;
if (!client) {
node.error('No engine configured.');
if (!client || !client.processInstances) {
node.error('No engine or processInstances API configured.');
return;
}
let timeMultiplier;
if (msg.payload.time_unit) {
timeMultiplier = msg.payload.time_unit == 'hours' ? 1 : 24;
} else {
timeMultiplier = config.time_unit == 'hours' ? 1 : 24;
const timeToUse = msg.payload.duration || config.duration;
if (!timeToUse || isNaN(timeToUse) || timeToUse <= 0) {
node.error('Invalid duration: must be a positive number.');
return;
}
const timeToUse = msg.payload.duration ? msg.payload.duration : config.duration;
const modelId = msg.payload.processModelId
? msg.payload.processModelId != ''
? msg.payload.processModelId
: undefined
: config.modelid != ''
? config.modelid
: undefined;
const isHours = msg.payload.time_unit
? msg.payload.time_unit.toLowerCase() === 'hours'
: config.time_unit.toLowerCase() === 'hours';
const multiplier = isHours ? 1 : 24;
const batchSize = config.batch_size || 100; // Konfigurierbare Batchgröße, Standardwert 100
const deletionDate = new Date(Date.now() - timeToUse * multiplier * 60 * 60 * 1000);
try {
const result = await client.processInstances.query({
processModelId: modelId
}, { identity: node.engine.identity });
const modelId = msg.payload.processModelId?.trim() || config.modelid?.trim();
if (!modelId) {
node.error('processModelId is not defined or empty.');
return;
}
let allInstances = result.processInstances.filter((instance) => instance.state != 'suspended' && instance.state != 'running');
const batchSize = config.batch_size || 100;
const today = new Date();
try {
const result = await client.processInstances.query(
{ processModelId: modelId,
finishedBefore: deletionDate,
state: ['finished', 'error', 'terminated'],
},
{ identity: node.engine.identity }
);
const oldTasks = allInstances.filter((instance) => {
const finishedDate = new Date(instance.finishedAt);
const diffInHours = (today - finishedDate) / (1000 * 60 * 60);
return diffInHours > Number(timeToUse) * timeMultiplier;
});
if (result.processInstances.length === 0) {
node.log(`No process instances to delete for Model-ID: ${modelId}`);
node.send(msg);
return;
}
const ids = oldTasks.map((obj) => obj.processInstanceId);
const ids = result.processInstances.map((obj) => obj.processInstanceId);
msg.payload = {
successfulDeletions: [],
failedDeletions: []
};
msg.payload = { successfulDeletions: [], failedDeletions: [] };

@@ -58,14 +58,15 @@ for (let i = 0; i < ids.length; i += batchSize) {

try {
await client.processInstances.deleteProcessInstances(batch, true, engine.identity);
msg.payload.successfulDeletions.push(...batch); // Erfolgreiche IDs hinzufügen
await client.processInstances.deleteProcessInstances(batch, true, node.engine.identity);
msg.payload.successfulDeletions.push(...batch);
} catch (deleteError) {
batch.forEach(id => {
msg.payload.failedDeletions.push({ id, error: deleteError.message }); // Fehler protokollieren
batch.forEach((id) => {
msg.payload.failedDeletions.push({ id, error: deleteError.message });
});
node.warn(`Failed to delete process instances in batch: ${batch.join(', ')}. Error: ${deleteError.message}`);
node.warn(`Failed to delete process instances in batch for Model-ID: ${modelId}: ${batch.join(', ')}. Error: ${deleteError.message}`);
}
}
node.send(msg);
} catch (queryError) {
node.error(`Failed to query process instances: ${queryError.message}`);
node.error(`Failed to query process instances for Model-ID: ${modelId}: ${queryError.message}`);
}

@@ -76,2 +77,2 @@ });

RED.nodes.registerType('processinstance-delete', ProcessInstanceDelete);
};
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc