maple.utils.retry.retry
- maple.utils.retry.retry(max_attempts: int = 3, delay: float = 1.0, backoff: float = 2.0, max_delay: float = 30.0, exceptions: ~typing.Tuple[~typing.Type[Exception], ...] = (<class 'Exception'>,), config: ~maple.utils.retry.RetryConfig | None = None) Callable[[Callable[[...], T]], Callable[[...], T]]
Decorator that adds automatic retry logic with exponential backoff.
Wraps a function to automatically retry on failure with configurable backoff strategy. Useful for handling transient failures in network operations, external API calls, or resource contention.
The decorator can be configured either by passing parameters directly or by providing a RetryConfig object. If both are provided, the config object takes precedence.
- Parameters:
max_attempts – Maximum number of execution attempts. Must be >= 1.
delay – Initial delay between retries in seconds. Must be >= 0.
backoff – Exponential backoff multiplier. Applied to delay after each failed attempt.
max_delay – Maximum delay cap in seconds. Prevents unbounded growth of retry intervals.
exceptions – Tuple of exception types to catch and retry. Only these exceptions trigger retries; others propagate immediately. Default is (Exception,) which catches all exceptions.
config – Optional RetryConfig object. If provided, overrides all other parameters.
- Returns:
A decorator function that wraps the target function with retry logic.