pynenc_rabbitmq.util.retry

Retry utilities with exponential backoff for RabbitMQ operations.

Provides resilient connection handling by retrying failed operations with configurable exponential backoff delays.

Key components:

  • calculate_backoff_delay: Computes delay for a given retry attempt

  • retry_with_backoff: Decorator/wrapper for retryable operations

  • RECOVERABLE_EXCEPTIONS: Tuple of exceptions that trigger retry

Module Contents

Functions

calculate_backoff_delay

Calculate exponential backoff delay for a given attempt.

retry_with_backoff

Execute an operation with exponential backoff retry on connection failures.

Data

API

pynenc_rabbitmq.util.retry.logger

‘getLogger(…)’

pynenc_rabbitmq.util.retry.T

‘TypeVar(…)’

pynenc_rabbitmq.util.retry.RECOVERABLE_EXCEPTIONS

()

pynenc_rabbitmq.util.retry.calculate_backoff_delay(attempt: int, initial_delay: float = 1.0, max_delay: float = 60.0, exponential_base: float = 2.0) float[source]

Calculate exponential backoff delay for a given attempt.

Parameters:
  • attempt – Current attempt number (0-indexed)

  • initial_delay – Initial delay in seconds

  • max_delay – Maximum delay cap in seconds

  • exponential_base – Base for exponential calculation

Returns:

Delay in seconds

pynenc_rabbitmq.util.retry.retry_with_backoff(operation: collections.abc.Callable[[], pynenc_rabbitmq.util.retry.T], operation_name: str, max_attempts: int = 0, initial_delay: float = 1.0, max_delay: float = 60.0, exponential_base: float = 2.0, on_retry: collections.abc.Callable[[int, Exception, float], None] | None = None) pynenc_rabbitmq.util.retry.T[source]

Execute an operation with exponential backoff retry on connection failures.

Parameters:
  • operation – Callable to execute

  • operation_name – Name for logging purposes

  • max_attempts – Maximum retry attempts (0 = infinite)

  • initial_delay – Initial delay in seconds before first retry

  • max_delay – Maximum delay between retries

  • exponential_base – Base for exponential backoff

  • on_retry – Optional callback called before each retry with (attempt, exception, delay)

Returns:

Result of the operation

Raises:

The last exception if max_attempts is reached