-
with_retry — Wrap a callable with retry-on-rate-limit / 5xx; never retries auth errors.
comicbox.formats.base.online.retry¶
source module comicbox.formats.base.online.retry
Exponential-backoff retry decorator for online API calls.
Wraps a callable that talks to an upstream API. Retries transient errors (rate-limit, 5xx) with exponential backoff up to max_retries. Honors the upstream’s retry_after hint when present (mokkari sets this on RateLimitError). Permanent failures — auth errors and not-found responses — are never retried.
Functions
source with_retry(*, max_retries: int = 5, sleep: Callable[[float], None] = time.sleep) → Callable[[Callable[…, T]], Callable[…, T]]
Wrap a callable with retry-on-rate-limit / 5xx; never retries auth errors.
Rate-limit errors get a separate retry budget (_MAX_RATE_LIMIT_RETRIES) and a longer delay schedule (_RATE_LIMIT_SCHEDULE) than other retriable failures. The generic 1-2-4-8-16s schedule tops out at 31s of total wait, which is far too short for hourly-cap recovery (ComicVine’s 200/hr can require several minutes to clear). The rate-limit schedule (30s, 1m, 2m, 5m, 10m) gives that window time to slide forward.
When the exception carries a retry_after attribute (mokkari does this), we honor it directly — server hint always wins over our blind schedules.