diff --git a/core/utils/retry.py b/core/utils/retry.py index 9dc58a3..036e59c 100644 --- a/core/utils/retry.py +++ b/core/utils/retry.py @@ -8,6 +8,7 @@ logger = logging.getLogger(__name__) +# Configure a clean file logging mechanism without side effects if not logger.handlers: handler = logging.FileHandler("retry.log") formatter = logging.Formatter( @@ -17,10 +18,14 @@ logger.addHandler(handler) logger.setLevel(logging.WARNING) -logging.basicConfig(filename="retry.log", level=logging.WARNING) def retry(max_retries: int = 3, base_delay: float = 1.0): + """ + Decorator to automatically retry both sync and async functions + upon hitting OpenAI API or Rate Limit errors with exponential backoff. + """ def decorator(func): + # Handle Asynchronous Functions if inspect.iscoroutinefunction(func): @wraps(func) @@ -43,6 +48,7 @@ async def async_wrapper(*args, **kwargs): return async_wrapper + # Handle Synchronous Functions else: @wraps(func) @@ -65,4 +71,4 @@ def sync_wrapper(*args, **kwargs): return sync_wrapper - return decorator + return decorator \ No newline at end of file