Model/backend/epc_client/_retry.py
Khalim Conn-Kowlessar d338be867b added missing files
2026-04-25 22:41:57 +00:00

23 lines
626 B
Python

import time
from typing import Callable, TypeVar
from backend.epc_client.exceptions import EpcRateLimitError
T = TypeVar("T")
def call_with_retry(
fn: Callable[[], T],
max_retries: int = 5,
backoff_base: float = 1.0,
backoff_multiplier: float = 2.0,
) -> T:
last_exc: EpcRateLimitError | None = None
for attempt in range(max_retries + 1):
try:
return fn()
except EpcRateLimitError as exc:
last_exc = exc
if attempt < max_retries:
time.sleep(backoff_base * (backoff_multiplier ** attempt))
raise last_exc # type: ignore[misc]