Skip to Content

Prozesse starten

Diese Seite zeigt, wie Sie neue Prozess-Instanzen in der ProcessCube® Engine starten.

Einfacher Start

import { Client } from '@processcube/client'; const client = new Client('http://localhost:8000'); async function startProcess() { console.log('Starte neue Prozess-Instanz'); const result = await client.startProcess('MyProcessKey'); console.log(`Prozess-Instanz gestartet: ${result.processInstanceId}`); console.log('Fertig!'); } startProcess().catch((error) => console.log('Fehler:', error.message));

Mit Eingabeparametern

Übergeben Sie Daten an den Prozess:

const result = await client.startProcess('OrderProcess', { customerName: 'Max Mustermann', orderAmount: 1500, items: ['Artikel1', 'Artikel2'], }); console.log(`Prozess-Instanz: ${result.processInstanceId}`); console.log(`Ergebnis: ${JSON.stringify(result.result)}`);

Auf End-Event warten

Warten Sie, bis der Prozess vollständig durchgelaufen ist:

async function startAndWait() { console.log('Starte Prozess und warte auf End-Event'); const result = await client.startProcessAndWait('MyProcessKey', { inputData: 'Test', }); console.log(`Prozess beendet mit ID: ${result.processInstanceId}`); console.log(`Rückgabewerte: ${JSON.stringify(result.result)}`); }

startProcessAndWait() wartet, bis der Prozess ein End-Event erreicht. Dies ist nützlich für synchrone Workflows.

Prozess-Ergebnis abrufen

Nach dem Start können Sie das Ergebnis überprüfen:

const result = await client.startProcessAndWait('CalculationProcess', { value1: 10, value2: 20, }); // Ergebnis aus dem Prozess if (result.result && result.result.sum) { console.log(`Berechnung: ${result.result.sum}`); }

Best Practices

Fehlerbehandlung

try { const result = await client.startProcess('OrderProcess', orderData); console.log('Prozess gestartet:', result.processInstanceId); } catch (error) { if (error.code === 'PROCESS_NOT_FOUND') { console.error('Prozess existiert nicht'); } else if (error.code === 'INVALID_INPUT') { console.error('Ungültige Eingabeparameter'); } else { console.error('Start fehlgeschlagen:', error.message); } }

Eingabedaten validieren

interface OrderInput { customerName: string; orderAmount: number; items: string[]; } function validateOrderInput(data: OrderInput): void { if (!data.customerName || data.customerName.length === 0) { throw new Error('customerName ist erforderlich'); } if (data.orderAmount <= 0) { throw new Error('orderAmount muss größer als 0 sein'); } if (!data.items || data.items.length === 0) { throw new Error('items dürfen nicht leer sein'); } } // Vor dem Start validieren const orderData: OrderInput = { customerName: 'Max Mustermann', orderAmount: 1500, items: ['Artikel1'], }; validateOrderInput(orderData); const result = await client.startProcess('OrderProcess', orderData);

Timeout für Long-Running Prozesse

// Für lange laufende Prozesse: nicht warten const result = await client.startProcess('LongRunningProcess', inputData); console.log(`Gestartet: ${result.processInstanceId}`); // Status später abfragen const instances = await client.getProcessInstances({ processInstanceId: result.processInstanceId, });

Mehrere Instanzen parallel starten

async function startMultipleInstances() { const orders = [ { customerName: 'Kunde 1', orderAmount: 100 }, { customerName: 'Kunde 2', orderAmount: 200 }, { customerName: 'Kunde 3', orderAmount: 300 }, ]; const promises = orders.map((order) => client.startProcess('OrderProcess', order)); const results = await Promise.all(promises); results.forEach((result, index) => { console.log(`Order ${index + 1}: ${result.processInstanceId}`); }); }

Nächste Schritte