o
    $i{
                     @   s   d dl Z d dlZd dlZd dlZd dlmZmZmZmZ e	e
Z			ddededeee  ded	ed
efddZ			ddedeee  ded	ed
ef
ddZdS )    N)AnyCallableListOptional
       fdescriptionmatchmax_attemptsmax_backoff_sreturnc                    s$  |dksJ d| dt |D ]}z
| |i |W   S  ty } zgt| |du p6t fdd|D }	|	rc|d |k rctd| |tdd	 }
td
|d  d| d|
 d t	
|
 n"|	rttd| d| d |dtd  d|d  d |dW Y d}~qd}~ww dS )ah  Retry a function with exponential backoff.

    Args:
        f: The function to retry.
        description: An imperative description of the function being retried. For
            example, "open the file".
        match: A list of strings to match in the exception message. If ``None``, any
            error is retried.
        max_attempts: The maximum number of attempts to retry.
        max_backoff_s: The maximum number of seconds to backoff.
        *args: Arguments to pass to the function.
        **kwargs: Keyword arguments to pass to the function.

    Returns:
        The result of the function.
       z%`max_attempts` must be positive. Got .Nc                 3   s    | ]}| v V  qd S N ).0patternexception_strr   N/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/_common/retry.py	<genexpr>+   s    
z"call_with_retry.<locals>.<genexpr>   g?g333333?z	Retrying z attempts to z after z	 seconds.z
Failed to z attempts. Raising.zDid not find a match for z. Raising after z
 attempts.)range	Exceptionstranyminrandomuniformloggerdebugtimesleep)r   r	   r
   r   r   argskwargsieis_retryablebackoffr   r   r   call_with_retry
   s8   r*   c                    s    dt dt f fdd}|S )z+Decorator-based version of call_with_retry.funcr   c                    s"   t   fdd}|S )Nc                     s   t  g| R i |S r   )r*   )r$   r%   )r	   r+   r
   r   r   r   r   innerJ   s   
z'retry.<locals>.decorator.<locals>.inner)	functoolswraps)r+   r,   r	   r
   r   r   )r+   r   	decoratorI   s   zretry.<locals>.decorator)r   )r	   r
   r   r   r0   r   r/   r   retryA   s   	r1   )Nr   r   )r-   loggingr   r"   typingr   r   r   r   	getLogger__name__r    r   intr*   r1   r   r   r   r   <module>   sH    


9
