ToolStabil
Velin Flow: Transaktionale Workflows
Orchestrierung komplexer Prozesse mit dem Saga Pattern - automatische Kompensation bei Fehlern.
Grundkonzepte
Step
Einzelne Aktion (z.B. Geld abbuchen)
Compensation
Gegen-Aktion (z.B. Geld zurückbuchen)
Snapshot
Gespeicherter Zustand vor einem Schritt
Flow definieren
use flow
struct OrderContext {
orderId: string,
userId: string,
amount: number
}
@Flow
fn processOrder(ctx: OrderContext) {
flow.snapshot_input(ctx);
// Schritte ausführen...
}Schritte mit Kompensation
@Flow
fn bookTrip(userId: string) {
// Schritt 1: Flug buchen
let flight = flow.step(
"book_flight",
|| flightService.book(userId, "Berlin", "New York"),
|result| flightService.cancel(result.bookingId) // Kompensation
);
// Schritt 2: Hotel buchen
// Wenn das hier fehlschlägt, wird automatisch der Flug storniert!
let hotel = flow.step(
"book_hotel",
|| hotelService.reserve(userId, "New York"),
|result| hotelService.cancel(result.reservationId)
);
// Schritt 3: E-Mail senden
flow.step(
"send_mail",
|| emailService.send(userId, "Reise gebucht!"),
|| log.info("Mail konnte nicht zurückgenommen werden.")
);
}State Management
// Status abfragen
let status = flow.get_status(flowId);
match status {
FlowStatus.Running => log.info("Läuft noch..."),
FlowStatus.Failed(err) => log.error("Fehler: " + err),
FlowStatus.Completed(res) => log.info("Fertig!")
}Retries konfigurieren
flow.step(
"payment",
|| paymentGateway.charge(amount),
|res| paymentGateway.refund(res.id)
).retry({
attempts: 3,
backoff: "exponential", // Warten: 1s, 2s, 4s
delay: "1s"
});Flow vs Pipeline
| Feature | @Flow | @VelinPipeline |
|---|---|---|
| Ziel | Zuverlässigkeit | Performance |
| Modus | Sequenziell | Parallel |
| Fehler | Rollback | Abbruch |
| Einsatz | Buchungen, Bestellungen | Datenanalyse, Batch |