(fn, max_attempts: int, attempt: int = 0)
Attempts to run a function that makes an external call, if the call fails
    on a connection error or timeout, it will be tried up to 5 more times.
Attempts to run a function that makes an external call, if the call fails
    on a connection error or timeout, it will be tried up to 5 more times.
Attempts to run a function that makes an external call if the call fails on a connection error or timeout it will be tried up to 5 more times .
def _connection_exception_retry(fn, max_attempts: int, attempt: int = 0):
    """Attempts to run a function that makes an external call, if the call fails
    on a connection error or timeout, it will be tried up to 5 more times.
    """
    try:
        return fn()
    except (
        requests.exceptions.ConnectionError,
        requests.exceptions.Timeout,
        requests.exceptions.ContentDecodingError,
    ) as exc:
        if attempt <= max_attempts - 1:
            fire_event(RetryExternalCall(attempt=attempt, max=max_attempts))
            time.sleep(1)
            _connection_exception_retry(fn, max_attempts, attempt + 1)
        else:
            raise ConnectionException('External connection exception occurred: ' + str(exc))
def _connection_exception_retry ( fn , max_attempts : int , attempt : int = 0 ) : try : return fn ( ) except ( requests . exceptions . ConnectionError , requests . exceptions . Timeout , requests . exceptions . ContentDecodingError , ) as exc : if attempt <= max_attempts - 1 : fire_event ( RetryExternalCall ( attempt = attempt , max = max_attempts ) ) time . sleep ( 1 ) _connection_exception_retry ( fn , max_attempts , attempt + 1 ) else : raise ConnectionException ( 'External connection exception occurred: ' + str ( exc ) )