babylon.utils.retry

Retry decorator for transient failure handling.

In the material world, systems fail. Networks drop. Databases timeout. The revolutionary must persevere.

Functions

retry_on_exception([max_retries, delay, ...])

Decorator that retries a function on specified exceptions.

babylon.utils.retry.retry_on_exception(max_retries=3, delay=1.0, backoff=2.0, exceptions=Exception, logger=None)[source]

Decorator that retries a function on specified exceptions.

Uses exponential backoff to avoid hammering failing resources. This is a materialist approach: we respect the physical constraints of the systems we depend on.

Parameters:
  • max_retries (int) – Maximum number of retry attempts

  • delay (float) – Initial delay between retries (seconds)

  • backoff (float) – Multiplier applied to delay after each retry

  • exceptions (type[Exception] | tuple[type[Exception], ...]) – Exception types that trigger a retry

  • logger (Logger | None) – Logger instance for retry messages

Return type:

Callable[[TypeVar(F, bound= Callable[..., Any])], TypeVar(F, bound= Callable[..., Any])]

Returns:

Decorated function with retry logic

Example

@retry_on_exception(max_retries=3, delay=1.0, exceptions=(ConnectionError,)) def fetch_data():

return requests.get(”https://api.example.com”)