Tinkex.API.Retry (Tinkex v0.3.4)
View SourceRetry logic with exponential backoff for Tinkex API requests.
Implements Python SDK parity for retry behavior:
- Exponential backoff with jitter
- Configurable max retries
- Status-based retry decisions (429, 408, 409, 5xx)
- Retry-After header support
- x-should-retry header override
Summary
Functions
Calculates retry delay with exponential backoff and jitter.
Executes a request with automatic retry logic.
Functions
@spec calculate_delay(non_neg_integer()) :: non_neg_integer()
Calculates retry delay with exponential backoff and jitter.
Python parity implementation:
- Base delay: INITIAL_RETRY_DELAY * 2^attempt
- Capped at: MAX_RETRY_DELAY
- Jitter: random value in range [0.75, 1.0]
Examples
iex> delay = calculate_delay(0)
iex> delay >= 375 and delay <= 500
true
iex> delay = calculate_delay(5)
iex> delay >= 7500 and delay <= 10000
true
@spec execute(Finch.Request.t(), atom(), timeout(), non_neg_integer(), boolean()) :: retry_result()
Executes a request with automatic retry logic.
Retries are governed by:
- max_retries configuration (no wall-clock timeout)
- Status codes (429, 408, 409, 5xx)
- Connection errors (transport, HTTP)
- x-should-retry header override
Options
request- Finch request to executepool- Connection pool nametimeout- Per-request timeout in millisecondsmax_retries- Maximum number of retry attemptsdump_headers?- Whether to log request details
Returns
{result, retry_count} where result is {:ok, response} or {:error, reason}
and retry_count is the number of retries performed.