Class: KubeMQ::Interceptors::RetryInterceptor Private

Inherits:
GRPC::ClientInterceptor
  • Object
show all
Defined in:
lib/kubemq/interceptors/retry_interceptor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

gRPC client interceptor that retries failed unary RPCs with exponential backoff.

Only unary (+request_response+) calls are retried; streaming RPCs pass through unchanged because retrying a partial stream is not safe.

Retryable gRPC status codes: UNAVAILABLE, ABORTED, DEADLINE_EXCEEDED.

See Also:

Constant Summary collapse

RETRYABLE_CODES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

gRPC status codes eligible for automatic retry.

[
  GRPC::Core::StatusCodes::UNAVAILABLE,
  GRPC::Core::StatusCodes::ABORTED,
  GRPC::Core::StatusCodes::DEADLINE_EXCEEDED
].freeze
DEFAULT_MAX_RETRIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Maximum number of retry attempts for unary RPCs.

3
DEFAULT_BASE_DELAY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Initial backoff delay in seconds.

0.1
DEFAULT_MULTIPLIER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Multiplier applied to delay after each retry attempt.

2.0

Instance Method Summary collapse

Constructor Details

#initialize(max_retries: DEFAULT_MAX_RETRIES, base_delay: DEFAULT_BASE_DELAY, multiplier: DEFAULT_MULTIPLIER) ⇒ RetryInterceptor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RetryInterceptor.

Parameters:

  • max_retries (Integer) (defaults to: DEFAULT_MAX_RETRIES)

    maximum retry attempts (default: DEFAULT_MAX_RETRIES)

  • base_delay (Float) (defaults to: DEFAULT_BASE_DELAY)

    initial backoff delay in seconds (default: DEFAULT_BASE_DELAY)

  • multiplier (Float) (defaults to: DEFAULT_MULTIPLIER)

    exponential backoff multiplier (default: DEFAULT_MULTIPLIER)



38
39
40
41
42
43
44
# File 'lib/kubemq/interceptors/retry_interceptor.rb', line 38

def initialize(max_retries: DEFAULT_MAX_RETRIES, base_delay: DEFAULT_BASE_DELAY,
               multiplier: DEFAULT_MULTIPLIER)
  super()
  @max_retries = max_retries
  @base_delay = base_delay
  @multiplier = multiplier
end

Instance Method Details

#bidi_streamer(requests:, call:, method:, metadata:, &block) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Passes bidirectional-streaming RPCs through without retry.

Parameters:

  • requests (Enumerator)

    the outbound request stream

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Enumerator)

    bidirectional response stream



87
88
89
# File 'lib/kubemq/interceptors/retry_interceptor.rb', line 87

def bidi_streamer(requests:, call:, method:, metadata:, &block)
  block.call(requests, call, method, )
end

#client_streamer(requests:, call:, method:, metadata:, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Passes client-streaming RPCs through without retry.

Parameters:

  • requests (Enumerator)

    the outbound request stream

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Object)

    the RPC response



76
77
78
# File 'lib/kubemq/interceptors/retry_interceptor.rb', line 76

def client_streamer(requests:, call:, method:, metadata:, &block)
  block.call(requests, call, method, )
end

#request_response(request:, call:, method:, metadata:, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes a unary RPC with automatic retry on transient failures.

Parameters:

  • request (Object)

    the outbound protobuf message

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Object)

    the RPC response

Raises:

  • (GRPC::BadStatus)

    after exhausting retries or on non-retryable errors



54
55
56
# File 'lib/kubemq/interceptors/retry_interceptor.rb', line 54

def request_response(request:, call:, method:, metadata:, &block)
  with_retry { block.call(request, call, method, ) }
end

#server_streamer(request:, call:, method:, metadata:, &block) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Passes server-streaming RPCs through without retry.

Parameters:

  • request (Object)

    the outbound protobuf message

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Enumerator)

    server response stream



65
66
67
# File 'lib/kubemq/interceptors/retry_interceptor.rb', line 65

def server_streamer(request:, call:, method:, metadata:, &block)
  block.call(request, call, method, )
end