def test_if_transient_error(): assert retry.if_transient_error(exceptions.InternalServerError("")) assert retry.if_transient_error(exceptions.TooManyRequests("")) assert retry.if_transient_error(exceptions.ServiceUnavailable("")) assert retry.if_transient_error(requests.exceptions.ConnectionError("")) assert retry.if_transient_error(requests.exceptions.ChunkedEncodingError("")) assert retry.if_transient_error(auth_exceptions.TransportError("")) assert not retry.if_transient_error(exceptions.InvalidArgument(""))
def is_transient_error(error): """Determine whether an error is transient. Returns: bool: True if error is transient, else False. """ if core_retry.if_transient_error(error): return True return isinstance(error, TRANSIENT_ERRORS)
def is_transient_error(error): """Determine whether an error is transient. Returns: bool: True if error is transient, else False. """ if core_retry.if_transient_error(error): return True method = getattr(error, "code", None) if method is not None: code = method() return code in TRANSIENT_CODES return False
def is_transient_error(error): """Determine whether an error is transient. Returns: bool: True if error is transient, else False. """ if core_retry.if_transient_error(error): return True if isinstance(error, grpc.Call): method = getattr(error, "code", None) if callable(method): code = method() return code in TRANSIENT_CODES return False
def google_cloud_retry_predicate(ex): """Given an exception from Google Cloud, determine if it's one in the listing of transient errors (determined by function google.api_core.retry.if_transient_error(exception)) or determine if triggered by a hash mismatch due to a bad download. This function will return a boolean to indicate if retry should be done, and is typically used with the google.api_core.retry.Retry as a decorator (predicate). Arguments: ex (Exception) : the exception passed from the decorated function Returns: boolean to indicate doing retry (True) or not (False) """ # Most likely case is Google API transient error if retry.if_transient_error(ex): return True # Could also be checksum mismatch of download if isinstance(ex, CheckSumMismatchException): return True return False
def test_if_transient_error(): assert retry.if_transient_error(exceptions.InternalServerError("")) assert retry.if_transient_error(exceptions.TooManyRequests("")) assert retry.if_transient_error(exceptions.ServiceUnavailable("")) assert not retry.if_transient_error(exceptions.InvalidArgument(""))
def retry_predicate(exception: Exception) -> Callable[[Exception], bool]: """"A function that will determine whether we should retry a given Google exception.""" return retry.if_transient_error(exception) or retry.if_exception_type( exceptions.GatewayTimeout)(exception)
def test_if_transient_error(): assert retry.if_transient_error(exceptions.InternalServerError("")) assert retry.if_transient_error(exceptions.TooManyRequests("")) assert not retry.if_transient_error(exceptions.InvalidArgument(""))
def test_if_transient_error(): assert retry.if_transient_error(exceptions.InternalServerError('')) assert retry.if_transient_error(exceptions.TooManyRequests('')) assert not retry.if_transient_error(exceptions.InvalidArgument(''))