ocpapi.workflows.retry#

Attributes#

Classes#

RateLimitLogging

Controls logging when rate limits are hit.

_wait_check_retry_after

Tenacity wait strategy that first checks whether RateLimitExceededException

Functions#

retry_api_calls(→ Any)

Decorator with sensible defaults for retrying calls to the OCP API.

Module Contents#

class ocpapi.workflows.retry.RateLimitLogging#

Controls logging when rate limits are hit.

logger: logging.Logger#

The logger to use.

action: str#

A short description of the action being attempted.

class ocpapi.workflows.retry._wait_check_retry_after(default_wait: tenacity.wait.wait_base, rate_limit_logging: RateLimitLogging | None = None)#

Bases: tenacity.wait.wait_base

Tenacity wait strategy that first checks whether RateLimitExceededException was raised and that it includes a retry-after value; if so wait, for that amount of time. Otherwise, fall back to the provided default strategy.

_default_wait#
_rate_limit_logging#
__call__(retry_state: tenacity.RetryCallState) float#

If a RateLimitExceededException was raised and has a retry_after value, return it. Otherwise use the default waiter method.

ocpapi.workflows.retry.NoLimitType#
ocpapi.workflows.retry.NO_LIMIT: NoLimitType = 0#
ocpapi.workflows.retry.retry_api_calls(max_attempts: int | NoLimitType = 3, rate_limit_logging: RateLimitLogging | None = None, fixed_wait_sec: float = 2, max_jitter_sec: float = 1) Any#

Decorator with sensible defaults for retrying calls to the OCP API.

Parameters:
  • max_attempts – The maximum number of calls to make. If NO_LIMIT, retries will be made forever.

  • rate_limit_logging – If not None, log statements will be generated using this configuration when a rate limit is hit.

  • fixed_wait_sec – The fixed number of seconds to wait when retrying an exception that does not include a retry-after value. The default value is sensible; this is exposed mostly for testing.

  • max_jitter_sec – The maximum number of seconds that will be randomly added to wait times. The default value is sensible; this is exposed mostly for testing.