Class: Gapic::CallOptions::RetryPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/call_options/retry_policy.rb

Overview

The policy for retrying failed RPC calls using an incremental backoff. A new object instance should be used for every RpcCall invocation.

Only errors orginating from GRPC will be retried.

Instance Method Summary collapse

Constructor Details

#initialize(retry_codes: nil, initial_delay: nil, multiplier: nil, max_delay: nil) ⇒ RetryPolicy

Create new API Call RetryPolicy.

Parameters:

  • initial_delay (Numeric) (defaults to: nil)

    client-side timeout

  • multiplier (Numeric) (defaults to: nil)

    client-side timeout

  • max_delay (Numeric) (defaults to: nil)

    client-side timeout



33
34
35
36
37
38
39
# File 'lib/gapic/call_options/retry_policy.rb', line 33

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

Instance Method Details

#call(error) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/gapic/call_options/retry_policy.rb', line 63

def call error
  return false unless retry? error

  delay!
  increment_delay!

  true
end

#delayObject

The current delay value.



59
60
61
# File 'lib/gapic/call_options/retry_policy.rb', line 59

def delay
  @delay || initial_delay
end

#initial_delayObject



45
46
47
# File 'lib/gapic/call_options/retry_policy.rb', line 45

def initial_delay
  @initial_delay || 1
end

#max_delayObject



53
54
55
# File 'lib/gapic/call_options/retry_policy.rb', line 53

def max_delay
  @max_delay || 15
end

#multiplierObject



49
50
51
# File 'lib/gapic/call_options/retry_policy.rb', line 49

def multiplier
  @multiplier || 1.3
end

#retry_codesObject



41
42
43
# File 'lib/gapic/call_options/retry_policy.rb', line 41

def retry_codes
  @retry_codes || []
end