HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/primordial/__pycache__/flow.cpython-39.pyc
a

�,�h��
@s�ddlZddlmZddlmZmZmZmZmZdZ	dZ
e�e�Z
Gdd�de�Zdeeeeed
�dd�Zdd
d�e
efeeeeeeeeeefed�dd�ZdS)�N)�sleep)�Any�Callable�Tuple�Type�Uniong�?�c@seZdZdZdS)�
RetryErrorz9A special type which signals the failure of a retry loop.N)�__name__�
__module__�__qualname__�__doc__�rr�@/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/primordial/flow.pyr	
sr	�
��?)�
test_function�	max_tests�
sleep_secs�count_trues�returncCs~d}d}d}||kr"t�d�|}||kr\|�}|durJ|d7}||krJq\|d7}t|�q"||krttd||f��|||fS)a�Attempt test_function over and over, waiting for a true value.

    Try a maximum of max_tests times.  Sleep sleep_secs in between each test.  Receive count_trues before moving on.

    wait_for_true is designed specifically to handle a design principle behind AWS or other clustered services: that you
    might succeed when making a request once and then fail very soon after. For example, when you make a REST API call
    against S3 to see if a bucket exists, the fact that you get a "True" response does not guarantee that you will get
    that same response to a request made very soon after.  In other words, it's for cases in which the goal is to
    produce a wait time for an eventually consistent external service to resolve your request.

    That's why wait_for_true lets you specify a threshold of how many trues you want to get before you're satisfied.

    :param test_function: a function to run whose result we will test for truthiness
    :param max_tests: limit to how many times we'll try test_function
    :param sleep_secs: how long to wait between tests
    :param count_trues: how many true results we need until we're totally true; this is useful with e.g. cluster
        tests, where we want a quorum of true answers before we're happy that the entire cluster is consistent (e.g.
        s3 put)
    :returns: the return value of the test function, the number of time it tried, and how many true results it found
    :raises RetryError: if the function "never" returned sufficiently many trues
    rNz9count_trues > max_tests, bumping max_tests to count_truesT�z6wait_for_true never succeeded %s times for function %s)�LOGGER�warningrr	)rrrrZ	itercount�retZtruesrrr�
wait_for_trues"

rcCs|tS)N)�DELAY_INCREASE_SECS)�xrrr�<lambda><�r)�action_functionr�backoff�max_attempts�exceptions_to_ignorerc
Cs�d}||kr�z|�WS|y�}zV|d7}||krJtd|t|�f�|�t�d||t|��t|�||�}WYd}~qd}~00qdS)a�Retry an e.g. network connection until it doesn't throw an exception of any kind.

    This is for single-success retry cases (e.g. wow, that TCP connection didn't get established because of high
    latency, let's dial back and try again in a bit).

    The action_function is expected to be of a sort that any expected exceptions are caught, as this will retry
    under /any/ exception.  The return value, if any, from the action_function is returned by retry on success.
    sleep_secs is the number of seconds to sleep between failures, and backoff defaults to adding DELAY_INCREASE_SECS
    to the prior value each time.  max_attempts is the limit of the number of retries in any case.

    On failure to complete the action_function without exception, raises RetryError.

    :param action_function: a function to run that we will retry if it raises any exception
    :param sleep_secs: how long to wait between tries
    :param backoff: a function that will expand the sleep duration based on what iteration we are on
    :param max_attempts: limit to how many times we'll try action_function
    :param exceptions_to_ignore: exception type or types to ignore; by default, ignores all Exception-derived
        exceptions
    :returns: the return value of the test function, the number of time it tried, and how many true results it found
    :raises RetryError: if the function "never" returned without an exception
    rrzFailure to retry %s: %sz.retry: pausing %s secs before retrying %s (%s)N)r	�strr�debugr)r rr!r"r#Zattempts�errr�retry:sr')rrr)�logging�timer�typingrrrrrrZMAX_RETRIES�	getLoggerr
r�	Exceptionr	�int�floatrr'rrrr�<module>s"
*��