You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the saga recovery scheduler demo and display its outcome.
621
-
621
+
622
622
Sets up an in-memory saga storage, creates a simulated interrupted saga and marks it stale, runs the recovery loop for three iterations (using the module's recovery_loop and recovery configuration constants), then loads and prints the final saga state.
Copy file name to clipboardExpand all lines: src/cqrs/saga/compensation.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ def __init__(
27
27
) ->None:
28
28
"""
29
29
Create a SagaCompensator configured to perform compensation of completed saga steps with retry and optional post-step callback.
30
-
30
+
31
31
Parameters:
32
32
saga_id: Identifier of the saga.
33
33
context: Saga execution context passed to step compensation handlers.
@@ -51,12 +51,12 @@ async def compensate_steps(
51
51
) ->None:
52
52
"""
53
53
Compensates completed saga steps in reverse order, applying retry logic and recording step statuses.
54
-
54
+
55
55
Compensates each handler from last to first, skipping steps already recorded as compensated in the saga history. Updates the saga status to COMPENSATING at the start and logs per-step statuses (STARTED, COMPLETED, FAILED) in storage. After a step completes, the optional on_after_compensate_step callback (if provided) is awaited. If any step fails after all retry attempts, the saga is marked as FAILED. If no completed steps are provided, no compensation is attempted and the saga is marked as FAILED.
56
-
56
+
57
57
Parameters:
58
58
completed_steps (list[SagaStepHandler[ContextT, typing.Any]]): Handlers corresponding to steps that completed during the saga; these will be compensated in reverse order.
Execute saga steps sequentially and yield each step result.
160
-
160
+
161
161
Implements the Strict Backward Recovery strategy: if the saga is in COMPENSATING or FAILED status, forward execution is never resumed. When the underlying storage provides create_run(), execution is performed within a per-saga run with checkpoint commits; otherwise the legacy run-less path is used.
162
162
Returns:
163
-
AsyncIterator[SagaStepResult[ContextT, typing.Any]]: An async iterator that yields the result for each executed saga step in order.
163
+
AsyncIterator[SagaStepResult[ContextT, typing.Any]]: An async iterator that yields the result for each executed saga step in order.
Execute the saga's configured steps, using the provided storage run for checkpointed operations when available, and perform recovery and compensation as required.
229
-
229
+
230
230
Parameters:
231
231
run (SagaStorageRun | None): Optional per-saga storage run. When provided, the run is used for loading saga state, creating run-scoped managers/executors, and committing at checkpoint boundaries. When None, the transaction's internal managers and executors are used.
232
-
232
+
233
233
Returns:
234
234
Async iterator that yields SagaStepResult values for each step that completes; each yielded result will include the transaction's saga_id.
235
-
235
+
236
236
Raises:
237
237
RuntimeError: If the saga was recovered in COMPENSATING or FAILED state and compensation was completed, forward execution is not allowed.
saga_id (uuid.UUID): Identifier of the saga to load.
97
97
read_for_update (bool): If True, acquire a database lock for update to prevent concurrent modifications.
98
-
98
+
99
99
Returns:
100
100
tuple[SagaStatus, dict[str, Any], int]: A tuple containing the saga's global status, the latest persisted context (JSON-serializable), and the current optimistic-locking version number.
101
101
"""
102
+
...
102
103
103
104
asyncdefget_step_history(
104
105
self,
105
106
saga_id: uuid.UUID,
106
107
) ->list[SagaLogEntry]:
107
108
"""
108
109
Retrieve the chronological step log for a saga.
109
-
110
+
110
111
Parameters:
111
112
saga_id (uuid.UUID): Identifier of the saga whose step history to retrieve.
112
-
113
+
113
114
Returns:
114
115
list[SagaLogEntry]: Ordered list of step log entries for the saga, from oldest to newest.
Create a scoped async run context for a single saga execution session with checkpointed commits.
346
-
348
+
347
349
The context manager yields a SagaStorageRun that provides the same mutation/read methods as the storage but does not commit automatically; the caller must call commit() or rollback() at desired checkpoints.
348
-
350
+
349
351
Returns:
350
352
contextlib.AbstractAsyncContextManager[SagaStorageRun]: Async context manager yielding a SagaStorageRun session.
351
-
353
+
352
354
Raises:
353
355
NotImplementedError: If the storage backend does not support scoped runs.
354
356
"""
355
-
raiseNotImplementedError("This storage does not support create_run()")
357
+
raiseNotImplementedError("This storage does not support create_run()")
0 commit comments