Module: Mihari::Mixins::Retriable

Included in:
Analyzers::Base, Emitters::Base
Defined in:
lib/mihari/mixins/retriable.rb

Constant Summary collapse

DEFAULT_ON =
[
  Errno::ECONNRESET,
  Errno::ECONNABORTED,
  Errno::EPIPE,
  OpenSSL::SSL::SSLError,
  Timeout::Error,
  RetryableError
]

Instance Method Summary collapse

Instance Method Details

#retry_on_error(times: 3, interval: 5, on: DEFAULT_ON) ⇒ nil

Retry on error



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mihari/mixins/retriable.rb', line 24

def retry_on_error(times: 3, interval: 5, on: DEFAULT_ON)
  try = 0
  begin
    try += 1
    yield
  rescue *on => e
    sleep interval
    retry if try < times
    raise e
  end
end