Skip to content

Commit

Permalink
hotfix: processinstance-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
luisthieme committed Oct 31, 2024
1 parent 996427a commit 995f5e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
27 changes: 16 additions & 11 deletions processinstance-delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
defaults: {
name: { value: '' },
engine: { value: '', type: 'processcube-engine-config' },
modelid: { value: '' },
time: { value: '', type: 'number' },
time_type: { value: 'hours' },
},
Expand All @@ -27,11 +28,15 @@
<input type="text" id="node-input-engine" placeholder="Engine-URL" />
</div>
<div class="form-row">
<label for="node-input-time"><i class="fa fa-tag"></i> Time</label>
<label for="node-input-modelid"><i class="fa fa-tag"></i> Model-ID</label>
<input type="text" id="node-input-modelid" />
</div>
<div class="form-row">
<label for="node-input-time"><i class="fa fa-tag"></i> Duration</label>
<input type="text" id="node-input-time" />
</div>
<div class="form-row">
<label for="node-input-time_type"><i class="fa fa-sliders"></i> Period</label>
<label for="node-input-time_type"><i class="fa fa-sliders"></i> Time Unit</label>
<select id="node-input-time_type" style="width: 70%;">
<option value="hours">Hours</option>
<option value="days">Days</option>
Expand All @@ -40,19 +45,19 @@
</script>

<script type="text/markdown" data-help-name="processinstance-delete">
Delete old instances of a process model in the ProcessCube.
Delete old instances of a process model in the ProcessCube.

## Inputs
## Inputs

: payload.time (number): The number of given time periods.
: payload.time_type ('hours' | 'days'): The type of time period to use.
: payload.time (number): The number of given time periods.
: payload.time_type ('hours' | 'days'): The type of time period to use.

## Outputs
## Outputs

: payload (string[]): The ids of the processinstances that were deleted.
: payload (string[]): The ids of the processinstances that were deleted.

### References
### References

- [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
- [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
- [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
- [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
</script>
21 changes: 12 additions & 9 deletions processinstance-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ module.exports = function (RED) {
}

const timeToUse = msg.payload.time ? msg.payload.time : config.time;
const modelId = msg.payload.processModelId
? msg.payload.processModelId != ''
? msg.payload.processModelId
: undefined
: config.modelid != ''
? config.modelid
: undefined;

try {
const fetchInstancesByState = async (state) => {
const result = await client.processInstances.query({ state });
return result.processInstances;
};

const finishedInstances = await fetchInstancesByState('finished');
const terminatedInstances = await fetchInstancesByState('terminated');
const errorInstances = await fetchInstancesByState('error');
const result = await client.processInstances.query({
processModelId: modelId,
identity: engine.identity,
});

let allInstances = [...finishedInstances, ...terminatedInstances, ...errorInstances];
let allInstances = result.processInstances.filter((instance) => instance.state != 'suspended');

const today = new Date();

Expand Down

0 comments on commit 995f5e0

Please sign in to comment.