class Gapic::CallOptions::RetryPolicy
Only errors orginating from GRPC will be retried.
every RpcCall invocation.
The policy for retrying failed RPC calls using an incremental backoff. A new object instance should be used for
#
def apply_defaults retry_policy
-
retry_policy
(Hash
) -- The policy for error retry. keys must match the arguments for
Other tags:
- Private: -
def apply_defaults retry_policy return unless retry_policy.is_a? Hash @retry_codes ||= convert_codes retry_policy[:retry_codes] @initial_delay ||= retry_policy[:initial_delay] @multiplier ||= retry_policy[:multiplier] @max_delay ||= retry_policy[:max_delay] self end
def call error
def call error return false unless retry? error delay! increment_delay! true end
def convert_codes input_codes
def convert_codes input_codes return nil if input_codes.nil? Array(input_codes).map do |obj| case obj when String ErrorCodes::ERROR_STRING_MAPPING[obj] when Integer obj end end.compact end
def delay
#
def delay @delay || initial_delay end
def delay!
def delay! # Call Kernel.sleep so we can stub it. Kernel.sleep delay end
def eql? other
- Private: - Equality test
def eql? other other.is_a?(RetryPolicy) && other.retry_codes == retry_codes && other.initial_delay == initial_delay && other.multiplier == multiplier && other.max_delay == max_delay end
def hash
- Private: - Hash code
def hash [retry_codes, initial_delay, multiplier, max_delay].hash end
def increment_delay!
#
def increment_delay! @delay = [delay * multiplier, max_delay].min end
def initial_delay
def initial_delay @initial_delay || 1 end
def initialize retry_codes: nil, initial_delay: nil, multiplier: nil, max_delay: nil
-
max_delay
(Numeric
) -- client-side timeout -
multiplier
(Numeric
) -- client-side timeout -
initial_delay
(Numeric
) -- client-side timeout
def initialize retry_codes: nil, initial_delay: nil, multiplier: nil, max_delay: nil @retry_codes = convert_codes retry_codes @initial_delay = initial_delay @multiplier = multiplier @max_delay = max_delay @delay = nil end
def max_delay
def max_delay @max_delay || 15 end
def multiplier
def multiplier @multiplier || 1.3 end
def retry? error
def retry? error (defined?(::GRPC) && error.is_a?(::GRPC::BadStatus) && retry_codes.include?(error.code)) || (error.respond_to?(:response_status) && retry_codes.include?(ErrorCodes.grpc_error_for(error.response_status))) end
def retry_codes
def retry_codes @retry_codes || [] end