Header menu logo TDesu.FSharp

Saga Module

Saga orchestrator — executes steps sequentially with automatic compensation on failure.

On failure, compensates all completed steps in reverse order (LIFO). If compensations also fail, returns AggregateException containing all errors.

Types

Type Description

Step<'ctx>

A saga step: an action that can be compensated (rolled back).

Functions and values

Function or value Description

Saga.run steps ctx

Full Usage: Saga.run steps ctx

Parameters:
    steps : Step<'ctx> list
    ctx : 'ctx

Returns: Task<Result<'ctx, exn>>

Runs saga steps sequentially. On failure, compensates all completed steps in reverse. Each compensation receives the context that was the output of that step. If compensations also fail, returns AggregateException containing the original + compensation errors. Ordered list of saga steps to execute sequentially. Initial context passed to the first step.

steps : Step<'ctx> list
ctx : 'ctx
Returns: Task<Result<'ctx, exn>>

Saga.step name execute compensate

Full Usage: Saga.step name execute compensate

Parameters:
    name : string
    execute : 'a -> Task<'a>
    compensate : 'a -> Task<unit>

Returns: Step<'a>

Creates a saga step. Descriptive name for the step (used in diagnostics). Async action that advances the saga context. Async rollback action invoked on failure.

name : string
execute : 'a -> Task<'a>
compensate : 'a -> Task<unit>
Returns: Step<'a>

Saga.stepNoCompensate name execute

Full Usage: Saga.stepNoCompensate name execute

Parameters:
    name : string
    execute : 'a -> Task<'a>

Returns: Step<'a>

Creates a saga step with no compensation (fire-and-forget). Descriptive name for the step (used in diagnostics). Async action that advances the saga context.

name : string
execute : 'a -> Task<'a>
Returns: Step<'a>

Type something to start searching.