Forge.RetryPolicy (Forge v0.1.1)
View SourceRetry policy configuration for stage execution.
Defines retry behavior including max attempts, backoff strategy, and which errors are retriable. Based on ADR-003.
Backoff Strategies
:jittered_exponential- Exponential backoff with ±25% jitter to avoid thundering herd:fixed- Constant delay between retries:linear- Linear increase in delay
Examples
# Default policy: 3 attempts with jittered exponential backoff
policy = Forge.RetryPolicy.new()
# Custom policy for LLM API calls
policy = Forge.RetryPolicy.new(
max_attempts: 5,
backoff: :jittered_exponential,
base_delay_ms: 1000,
max_delay_ms: 30_000,
retriable_errors: [429, 500, 502, 503, 504]
)
# No retries for deterministic stages
policy = Forge.RetryPolicy.new(max_attempts: 1)
Summary
Functions
Computes the delay in milliseconds for a given attempt.
Returns the default retry policy as specified in ADR-003.
Creates a new retry policy with given options.
Types
@type backoff_strategy() :: :jittered_exponential | :fixed | :linear
@type t() :: %Forge.RetryPolicy{ backoff: backoff_strategy(), base_delay_ms: pos_integer(), max_attempts: pos_integer(), max_delay_ms: pos_integer(), retriable_errors: retriable_errors() }
Functions
Computes the delay in milliseconds for a given attempt.
Examples
iex> policy = Forge.RetryPolicy.new(backoff: :fixed, base_delay_ms: 500)
iex> Forge.RetryPolicy.compute_delay(1, policy)
500
iex> policy = Forge.RetryPolicy.new(backoff: :linear, base_delay_ms: 1000)
iex> Forge.RetryPolicy.compute_delay(2, policy)
2000
Returns the default retry policy as specified in ADR-003.
Creates a new retry policy with given options.
Options
:max_attempts- Maximum number of attempts (default: 3):backoff- Backoff strategy (default: :jittered_exponential):base_delay_ms- Base delay in milliseconds (default: 1000):max_delay_ms- Maximum delay in milliseconds (default: 60_000):retriable_errors- Which errors to retry (default: :all):all- Retry all errors:none- Don't retry any errors- List of HTTP status codes, exception modules, or error atoms