Jido.Exec.Retry
(Jido Action v2.0.0)
View Source
Retry logic and backoff calculations for action execution.
This module centralizes retry behavior, including:
- Exponential backoff calculations with capping
- Retry decision logic based on error type and attempt count
- Retry option processing and validation
Summary
Functions
Calculate exponential backoff time for a retry attempt.
Get default retry configuration values.
Execute a retry with proper backoff and logging.
Extract and validate retry options from the provided opts.
Determine if an action should be retried based on the error and attempt count.
Functions
@spec calculate_backoff(non_neg_integer(), non_neg_integer()) :: non_neg_integer()
Calculate exponential backoff time for a retry attempt.
Uses exponential backoff with a maximum cap of 30 seconds.
Parameters
retry_count: The current retry attempt number (0-based)initial_backoff: The initial backoff time in milliseconds
Returns
The calculated backoff time in milliseconds, capped at 30,000ms.
Examples
iex> Jido.Exec.Retry.calculate_backoff(0, 250)
250
iex> Jido.Exec.Retry.calculate_backoff(1, 250)
500
iex> Jido.Exec.Retry.calculate_backoff(2, 250)
1000
@spec default_retry_config() :: keyword()
Get default retry configuration values.
Returns
A keyword list with default retry configuration:
:max_retries: Default maximum retry attempts:backoff: Default initial backoff time in milliseconds
@spec execute_retry( module(), non_neg_integer(), non_neg_integer(), non_neg_integer(), keyword(), function() ) :: any()
Execute a retry with proper backoff and logging.
This function handles the retry orchestration including:
- Calculating the backoff time
- Logging the retry attempt
- Sleeping for the backoff period
Parameters
action: The action module being retriedretry_count: The current retry attempt numbermax_retries: The maximum number of retries allowedinitial_backoff: The initial backoff time in millisecondsopts: Options for logging and other behaviorretry_fn: Function to call for the actual retry attempt
Returns
The result of calling retry_fn.
Extract and validate retry options from the provided opts.
Parameters
opts: The options keyword list to extract retry config from
Returns
A keyword list with validated retry configuration values.
@spec should_retry?(any(), non_neg_integer(), non_neg_integer(), keyword()) :: boolean()
Determine if an action should be retried based on the error and attempt count.
Parameters
error: The error that occurred during executionretry_count: The current retry attempt numbermax_retries: The maximum number of retries allowedopts: Additional options (currently unused but reserved for future use)
Returns
true if the action should be retried, false otherwise.
Examples
iex> Jido.Exec.Retry.should_retry?({:error, "network error"}, 0, 3, [])
true
iex> Jido.Exec.Retry.should_retry?({:error, "network error"}, 3, 3, [])
false