o
    RDi                     @  sv   d dl mZ d dlZd dlmZmZ 	 dZdZdZdZ	eeee	fdddZ
eeee	fdddZeeee	fdddZdS )    )annotationsN)CallableIterator         Tfactorintbasecapenable_jitterboolreturnCallable[..., Iterator[int]]c                       fdd}|S )a7  Randomly chooses between exponential and constant backoff. Uses equal jitter.

    Args:
        factor (int): Exponential base for the exponential term.
        base (int): Initial backoff time in seconds. Constant coefficient for the exponential term.
        cap (int): Maximum backoff time in seconds.
        enable_jitter (int): Whether to enable equal jitter on computed durations. For details see
            https://www.awsarchitectureblog.com/2015/03/backoff.html

    Returns:
        Callable: generator function implementing the mixed backoff policy
    c                  3  sp    d}  }|V  	 | d7 } t ddg}rd| | nd}tt ||  |   | g}t|}|V  q	)Nr   Tr   g      ?)randomchoicer	   min)cntsleepmult_factorjitter_amountr
   r   r   r    ]/var/www/Datamplify/venv/lib/python3.10/site-packages/snowflake/connector/backoff_policies.py	generator7   s    
z mixed_backoff.<locals>.generatorr   r   r
   r   r   r   r   r   r   mixed_backoff$   s   r   c                   r   )a  Standard linear backoff. Uses full jitter.

    Args:
        factor (int): Linear increment every iteration.
        base (int): Initial backoff time in seconds.
        cap (int): Maximum backoff time in seconds.
        enable_jitter (int): Whether to enable full jitter on computed durations. For details see
            https://www.awsarchitectureblog.com/2015/03/backoff.html

    Returns:
        Callable: generator function implementing the linear backoff policy
    c                  3  s8     } | V  	 | 7 } t | } rtd| n| V  qNTr   r   r   randintr   r   r   r   r   a      
z!linear_backoff.<locals>.generatorr   r   r   r   r   linear_backoffN      r$   c                   r   )a  Standard exponential backoff. Uses full jitter.

    Args:
        factor (int): Exponential base for the exponential term.
        base (int): Initial backoff time in seconds. Constant coefficient for the exponential term.
        cap (int): Maximum backoff time in seconds.
        enable_jitter (int): Whether to enable full jitter on computed durations. For details see
            https://www.awsarchitectureblog.com/2015/03/backoff.html

    Returns:
        Callable: generator function implementing the exponential backoff policy
    c                  3  s8     } | V  	 | 9 } t | } rtd| n| V  qr   r    r"   r   r   r   r      r#   z&exponential_backoff.<locals>.generatorr   r   r   r   r   exponential_backoffo   r%   r&   )
r   r	   r
   r	   r   r	   r   r   r   r   )
__future__r   r   typingr   r   DEFAULT_BACKOFF_FACTORDEFAULT_BACKOFF_BASEDEFAULT_BACKOFF_CAPDEFAULT_ENABLE_JITTERr   r$   r&   r   r   r   r   <module>   s.    +"