Jido. Exec. Compensation
(Jido Action v2.3.0)
View Source
Handles error compensation logic for Jido actions.
This module provides functionality to execute compensation actions when
an action fails, if the action implements the on_error/4 callback and
has compensation enabled in its metadata.
Summary
Functions
Checks if compensation is enabled for the given action.
Handles action errors by executing compensation if enabled.
Types
@type action() :: module()
@type context() :: map()
@type exec_result() :: {:ok, map()} | {:ok, map(), any()} | {:error, Exception.t()} | {:error, Exception.t(), any()}
@type params() :: map()
@type run_opts() :: Jido.Exec.run_opts()
Functions
Checks if compensation is enabled for the given action.
Compensation is enabled if:
- The action's metadata includes compensation configuration with
enabled: true - The action exports the
on_error/4function
Parameters
action: The action module to check
Returns
trueif compensation is enabled and availablefalseotherwise
@spec handle_error( action(), params(), context(), Exception.t() | {Exception.t(), any()}, run_opts() ) :: exec_result()
Handles action errors by executing compensation if enabled.
This is the main entry point for error handling with compensation.
If compensation is enabled, it will execute the action's on_error/4 callback
within a timeout. If compensation is disabled, it returns the original error.
Parameters
action: The action module that failedparams: The parameters that were passed to the actioncontext: The context that was passed to the actionerror_or_tuple: The error from the failed action, either an Exception or {Exception, directive}opts: Execution options including timeout
Returns
{:error, compensated_error}or{:error, compensated_error, directive}if compensation was attempted{:error, original_error}or{:error, original_error, directive}if compensation is disabled