Beispiel #1
0
 def handler(*args, **kwargs):
     """
     Wraps rpc errors as Flyte exceptions and handles authentication the client.
     :param args:
     :param kwargs:
     :return:
     """
     max_retries = 3
     max_wait_time = 1000
     try:
         for i in range(max_retries):
             try:
                 return fn(*args, **kwargs)
             except _RpcError as e:
                 if e.code() == _GrpcStatusCode.UNAUTHENTICATED:
                     # Always retry auth errors.
                     if i == (max_retries - 1):
                         # Exit the loop and wrap the authentication error.
                         raise _user_exceptions.FlyteAuthenticationException(_six.text_type(e))
                     refresh_handler_fn = _get_refresh_handler(_creds_config.AUTH_MODE.get())
                     refresh_handler_fn(args[0])
                 else:
                     # No more retries if retry=False or max_retries reached.
                     if (retry is False) or i == (max_retries - 1):
                         raise
                     else:
                         # Retry: Start with 200ms wait-time and exponentially back-off upto 1 second.
                         wait_time = min(200 * (2 ** i), max_wait_time)
                         _logging.error(f"Non-auth RPC error {e}, sleeping {wait_time}ms and retrying")
                         time.sleep(wait_time / 1000)
     except _RpcError as e:
         if e.code() == _GrpcStatusCode.ALREADY_EXISTS:
             raise _user_exceptions.FlyteEntityAlreadyExistsException(_six.text_type(e))
         else:
             raise
Beispiel #2
0
 def handler(*args, **kwargs):
     """
     Wraps rpc errors as Flyte exceptions and handles authentication the client.
     :param args:
     :param kwargs:
     :return:
     """
     retries = 2
     try:
         for i in range(retries):
             try:
                 return fn(*args, **kwargs)
             except _RpcError as e:
                 if e.code() == _GrpcStatusCode.UNAUTHENTICATED:
                     if i == (retries - 1):
                         # Exit the loop and wrap the authentication error.
                         raise _user_exceptions.FlyteAuthenticationException(
                             _six.text_type(e))
                     refresh_handler_fn = _get_refresh_handler(
                         _creds_config.AUTH_MODE.get())
                     refresh_handler_fn(args[0])
                 else:
                     raise
     except _RpcError as e:
         if e.code() == _GrpcStatusCode.ALREADY_EXISTS:
             raise _user_exceptions.FlyteEntityAlreadyExistsException(
                 _six.text_type(e))
         else:
             raise
Beispiel #3
0
 def handler(*args, **kwargs):
     try:
         return fn(*args, **kwargs)
     except _RpcError as e:
         if e.code() == _GrpcStatusCode.ALREADY_EXISTS:
             raise _user_exceptions.FlyteEntityAlreadyExistsException(_six.text_type(e))
         else:
             raise