Compensation API Reference
Details on how the compensation mechanism (Saga Pattern) works in Orchestrix.
The compensate Function
Defined in StepOptions.
ts
compensate?: (ctx: FlowContext<TInput>) => Promise<void> | void;Execution Rules
- Reverse Order: Compensations run in reverse order of step completion.
- Trigger: Triggered when a subsequent step fails permanently (exhausts retries) or times out.
- Context Access: The compensation function has full access to the
FlowContext, allowing it to read data stored during the original step execution. - Error Handling: If a compensation function itself fails, Orchestrix will catch the error, trigger the
onCompensationErrorhook, and continue with the next compensation in the queue.
Related Hooks
onCompensate: Triggered before a compensation starts.onCompensateComplete: Triggered after a compensation finishes successfully.