
    %`i{
                         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j	        e
          Z	 	 	 ddededeee                  ded	ed
efdZ	 	 	 ddedeee                  ded	ed
ef
dZdS )    N)AnyCallableListOptional
       fdescriptionmatchmax_attemptsmax_backoff_sreturnc                 l   |dk    sJ d| d            t          |          D ]}	  | |i |c S # t          $ r}t          |          |du pt          fd|D                       }	|	rn|dz   |k     ret	          d|z  |          t          j        dd          z  }
t                              d	|dz    d
| d|
 d           t          j
        |
           nK|	r"t                              d| d| d           n$t                              d d|dz    d           |dY d}~d}~ww xY 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       K   | ]}|v V  	d S N ).0patternexception_strs     e/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_common/retry.py	<genexpr>z"call_with_retry.<locals>.<genexpr>+   s9       0 0-4=(0 0 0 0 0 0       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   s              @r   call_with_retryr-   
   s   4 1UlUUU<   " "	"1d%f%%%%% 	" 	" 	"FFM D= C 0 0 0 08=0 0 0 - -L  "A 4 4adM22fnS#6N6NOX!XX+XXgXXX   
7#### LLZ[ZZZZZ    LLbMbbSTUVSVbbb   T! $####	"" "s   3
D1C)D,,D1c                 <     dt           dt           f fd}|S )z+Decorator-based version of call_with_retry.funcr   c                 P     t          j                    fd            }|S )Nc                  ,    t          g| R i |S r   )r-   )r'   r(   r
   r/   r   r   r   s     r   innerz'retry.<locals>.decorator.<locals>.innerJ   s:    "k5,HL  PV  r   )	functoolswraps)r/   r2   r
   r   r   r   s   ` r   	decoratorzretry.<locals>.decoratorI   sM    				 	 	 	 	 	 	 	 
		
 r   )r   )r
   r   r   r   r5   s   ```` r   retryr6   A   sI     X          r   )Nr   r   )r3   loggingr!   r%   typingr   r   r   r   	getLogger__name__r#   r   intr-   r6   r   r   r   <module>r<      s-          0 0 0 0 0 0 0 0 0 0 0 0		8	$	$ "&4" 4"4"4" DI4" 	4"
 4" 	4" 4" 4" 4"r "&	 DI  	
      r   