proxywhirl.retry.policy

Retry policy configuration and backoff strategies.

Classes

BackoffStrategy

Retry backoff timing strategy.

RetryPolicy

Configuration for retry behavior.

Module Contents

class proxywhirl.retry.policy.BackoffStrategy[source]

Bases: str, enum.Enum

Retry backoff timing strategy.

Initialize self. See help(type(self)) for accurate signature.

class proxywhirl.retry.policy.RetryPolicy(/, **data)[source]

Bases: pydantic.BaseModel

Configuration for retry behavior.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

calculate_delay(attempt, previous_delay=None)[source]

Calculate delay for given attempt number (0-indexed).

Uses AWS decorrelated jitter algorithm when jitter is enabled to prevent the thundering herd problem. The decorrelated jitter ensures that retry delays depend on previous delay values, spreading retries across time.

AWS decorrelated jitter formula:

delay = min(cap, random(base, previous_delay * 3))

Reference: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/

Parameters:
  • attempt (int) – The attempt number (0 for first retry, 1 for second, etc.)

  • previous_delay (float | None) – The delay from the previous attempt (for decorrelated jitter). If None and jitter is enabled, uses base_delay as seed.

Returns:

Delay in seconds before the next retry attempt

Return type:

float

classmethod validate_status_codes(v)[source]

Validate that status codes are 5xx errors.

Parameters:

v (list[int])

Return type:

list[int]