Complete the code to define a saga step that triggers a local transaction.
def saga_step(): # Start local transaction [1]() # Proceed to next step
The saga step must begin a local transaction before processing.
Complete the code to send a compensation event when a saga step fails.
def handle_failure(): # Send compensation event [1]('compensate')
Compensation is done by sending a compensation event to undo previous steps.
Fix the error in the saga coordinator code to correctly handle step completion.
def saga_coordinator(event): if event.type == 'step_completed': [1]() # Proceed to next saga step
When a step completes, the coordinator triggers the next step in the saga.
Fill both blanks to define a saga step that executes a local transaction and sends a success event.
def execute_step(): [1]() # Commit transaction [2]('step_completed') # Notify coordinator
The step commits its transaction and then sends a completion event.
Fill all three blanks to implement a saga step that begins a transaction, handles failure by sending compensation, and commits on success.
def saga_step_handler(): [1]() # Begin transaction try: process_local_transaction() [2]() # Commit transaction except Exception: [3]('compensate') # Send compensation event
The step begins a transaction, commits if successful, and sends a compensation event if it fails.