Tinkex.API.RetryConfig (Tinkex v0.3.4)

View Source

Retry configuration with Python SDK parity.

Implements retry delay calculation and status code classification matching the Python SDK's _base_client.py.

Python SDK Reference

From tinker/_constants.py:

  • INITIAL_RETRY_DELAY = 0.5 (seconds)
  • MAX_RETRY_DELAY = 10.0 (seconds)

From tinker/_base_client.py _calculate_retry_timeout:

  • Exponential backoff: sleep_seconds = min(INITIAL_RETRY_DELAY * pow(2.0, nb_retries), MAX_RETRY_DELAY)
  • Jitter: jitter = 1 - 0.25 * random() (range 0.75-1.0)
  • Final: timeout = sleep_seconds * jitter

From tinker/_base_client.py _should_retry:

  • Retries on status codes: 408, 409, 429, 5xx
  • No wall-clock timeout; governed by max_retries only

Summary

Functions

Create a new retry config with the given options.

Calculate retry delay for the given attempt number.

Calculate retry delay with custom initial and max delays.

Check if a status code is retryable per Python SDK rules.

Types

t()

@type t() :: %Tinkex.API.RetryConfig{
  initial_delay_ms: pos_integer(),
  max_delay_ms: pos_integer(),
  max_retries: non_neg_integer()
}

Functions

new(opts \\ [])

@spec new(keyword()) :: t()

Create a new retry config with the given options.

retry_delay(attempt)

@spec retry_delay(non_neg_integer()) :: non_neg_integer()

Calculate retry delay for the given attempt number.

Uses Python SDK formula:

  • Base delay: initial_delay * 2^attempt
  • Capped at max_delay
  • Jitter: multiplied by random value in [0.75, 1.0]

Examples

iex> delay = Tinkex.API.RetryConfig.retry_delay(0)
iex> delay >= 375 and delay <= 500
true

retry_delay(attempt, initial_delay_ms, max_delay_ms)

@spec retry_delay(non_neg_integer(), pos_integer(), pos_integer()) ::
  non_neg_integer()

Calculate retry delay with custom initial and max delays.

retryable_status?(status)

@spec retryable_status?(integer()) :: boolean()

Check if a status code is retryable per Python SDK rules.

Python retries on: 408, 409, 429, 5xx