Prozess-Instanzen abfragen
Diese Seite zeigt, wie Sie laufende und beendete Prozess-Instanzen in der Engine abfragen.
Grundlegendes Beispiel
import { Client } from '@processcube/client';
const client = new Client('http://localhost:8000');
async function queryInstances() {
// Alle Instanzen eines Prozesses abrufen
const instances = await client.getProcessInstances({
processKey: 'OrderProcess',
});
instances.forEach((instance) => {
console.log(`Instanz: ${instance.processInstanceId}`);
console.log(`Status: ${instance.state}`);
console.log(`Gestartet: ${instance.createdAt}`);
console.log('─────────────────────');
});
}
queryInstances().catch(console.error);Query-Parameter
Nach Status filtern
// Nur laufende Instanzen
const runningInstances = await client.getProcessInstances({
processKey: 'OrderProcess',
state: 'running',
});
// Nur beendete Instanzen
const finishedInstances = await client.getProcessInstances({
processKey: 'OrderProcess',
state: 'finished',
});
// Terminierte Instanzen
const terminatedInstances = await client.getProcessInstances({
processKey: 'OrderProcess',
state: 'terminated',
});Nach Zeitraum filtern
// Instanzen der letzten 24 Stunden
const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000);
const recentInstances = await client.getProcessInstances({
processKey: 'OrderProcess',
startedAfter: yesterday,
});
console.log(`${recentInstances.length} Instanzen in den letzten 24 Stunden`);Spezifische Instanz abrufen
const instances = await client.getProcessInstances({
processInstanceId: 'instance-123',
});
const instance = instances[0];
if (instance) {
console.log(`Status: ${instance.state}`);
console.log(`Erstellt: ${instance.createdAt}`);
console.log(`Aktualisiert: ${instance.updatedAt}`);
}Prozess-Status
Mögliche Stati für Prozess-Instanzen:
| Status | Beschreibung |
|---|---|
running | Prozess läuft aktuell |
finished | Prozess erfolgreich beendet |
terminated | Prozess wurde manuell beendet |
error | Prozess ist in einem Fehlerzustand |
suspended | Prozess ist pausiert |
Kombination von Filtern
// Komplexe Query
const instances = await client.getProcessInstances({
processKey: 'OrderProcess',
state: 'running',
startedAfter: new Date('2025-01-01'),
startedBefore: new Date('2025-12-31'),
});
console.log(`Gefundene Instanzen: ${instances.length}`);Best Practices
Paginierung bei großen Ergebnissen
async function getAllInstances(processKey: string) {
const pageSize = 100;
let offset = 0;
const allInstances = [];
while (true) {
const instances = await client.getProcessInstances({
processKey,
limit: pageSize,
offset,
});
allInstances.push(...instances);
if (instances.length < pageSize) {
break; // Keine weiteren Instanzen
}
offset += pageSize;
}
return allInstances;
}Monitoring Dashboard
async function getProcessStatistics(processKey: string) {
const instances = await client.getProcessInstances({ processKey });
const stats = {
total: instances.length,
running: instances.filter((i) => i.state === 'running').length,
finished: instances.filter((i) => i.state === 'finished').length,
terminated: instances.filter((i) => i.state === 'terminated').length,
error: instances.filter((i) => i.state === 'error').length,
};
console.log(`=== ${processKey} Statistics ===`);
console.log(`Total: ${stats.total}`);
console.log(`Running: ${stats.running}`);
console.log(`Finished: ${stats.finished}`);
console.log(`Terminated: ${stats.terminated}`);
console.log(`Error: ${stats.error}`);
return stats;
}Fehlerbehandlung
try {
const instances = await client.getProcessInstances({
processKey: 'OrderProcess',
state: 'running',
});
if (instances.length === 0) {
console.log('Keine laufenden Instanzen gefunden');
return;
}
// Verarbeite Instanzen...
} catch (error) {
console.error('Query fehlgeschlagen:', error.message);
}Nächste Schritte
- Prozess-Instanzen beenden - Laufende Instanzen stoppen
- FlowNode-Instanzen - Detaillierte Ausführungshistorie
- Prozesse starten - Neue Instanzen erstellen