Module: CDP::Retryable

Included in:
Client, Persistency
Defined in:
lib/cdp/retryable.rb

Constant Summary collapse

DEFAULT_CDP_CLIENT_RETRYABLE_ERRORS =
'Errno::ECONNRESET,Errno::ECONNREFUSED,GRPC::ResourceExhausted,GRPC::Unavailable'
CDP_CLIENT_RETRYABLE_ERRORS =
[
  ENV.fetch('CDP_CLIENT_RETRYABLE_ERRORS', DEFAULT_CDP_CLIENT_RETRYABLE_ERRORS).split(',')
].flatten

Instance Method Summary collapse

Instance Method Details

#retry_block(limit: 3, backoff: 1) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cdp/retryable.rb', line 11

def retry_block(limit: 3, backoff: 1)
  tries = 0

  begin
    yield
  rescue => e
    if CDP_CLIENT_RETRYABLE_ERRORS.include?(e.class.to_s) && tries < limit
      sleep backoff * tries
      tries += 1
      retry
    end

    raise
  end
end