Notification Handler
Der Notification Handler ermoeglicht es, auf Benachrichtigungen der Engine zu reagieren und eigene Logik auszufuehren.
Funktionsweise
Die Engine sendet bei bestimmten Ereignissen Notifications. Mit dem Notification Handler koennen Extensions auf diese Ereignisse subscriben.
Verfuegbare Notifications
| Methode | Ereignis | Anwendungsfall |
|---|---|---|
onProcessStarted | Prozessinstanz gestartet | Logging, Audit-Trail |
onProcessFinished | Prozessinstanz erfolgreich beendet | Benachrichtigungen, Cleanup |
onProcessError | Prozessinstanz mit Fehler beendet | Alerting, Incident-Management |
onUserTaskWaiting | User Task wartet auf Bearbeitung | E-Mail-Benachrichtigung, Push-Notification |
onUserTaskFinished | User Task abgeschlossen | Logging, naechste Schritte triggern |
Beispiel: Alle Events loggen
import { Engine } from '@5minds/processcube_engine_sdk';
export function onLoad(engineObject: Engine) {
engineObject.notifications.onProcessStarted((notification) => {
console.log('Prozess gestartet:', notification.processModelId, notification.processInstanceId);
});
engineObject.notifications.onProcessFinished((notification) => {
console.log('Prozess beendet:', notification.processModelId, notification.processInstanceId);
});
engineObject.notifications.onProcessError((notification) => {
console.error('Prozess-Fehler:', notification.processModelId, notification.error);
});
engineObject.notifications.onUserTaskWaiting((notification) => {
console.log('User Task wartet:', notification.flowNodeId, notification.processInstanceId);
});
engineObject.notifications.onUserTaskFinished((notification) => {
console.log('User Task beendet:', notification.flowNodeId, notification.processInstanceId);
});
}Beispiel: E-Mail bei User Task
import { Engine } from '@5minds/processcube_engine_sdk';
export function onLoad(engineObject: Engine) {
engineObject.notifications.onUserTaskWaiting(async (notification) => {
const assignedUsers = notification.assignedUsers ?? [];
for (const userId of assignedUsers) {
await sendEmail({
to: `${userId}@company.com`,
subject: `Neue Aufgabe: ${notification.flowNodeName}`,
body: `Sie haben eine neue Aufgabe im Prozess ${notification.processModelId}.`,
});
}
});
}Die Notification-Callbacks werden asynchron ausgefuehrt und blockieren nicht die Prozessausfuehrung. Fehler in Callbacks fuehren nicht zum Abbruch des Prozesses.
Abgrenzung zu anderen Extensions
| Extension | Zweck |
|---|---|
| Notification Handler | Reagieren auf Engine-Events innerhalb der Engine |
| RabbitMQ | Events an externe Systeme weiterleiten |
| Monitoring | Metriken aggregieren und exportieren |