module KfcFetch
Constants
- DEFAULT_MAX_ATTEMPTS
- DEFAULT_RETRY_DELAY
- TRANSIENT_ERRORS
Public Instance Methods
Source
# File lib/kfc_fetch.rb, line 37 def transient_error?(error) case error when OpenURI::HTTPError status = error.io.status[0].to_i status >= 500 when Timeout::Error, Errno::ECONNRESET, Errno::ETIMEDOUT, Net::OpenTimeout, Net::ReadTimeout true else false end end
Source
# File lib/kfc_fetch.rb, line 22 def with_retry(max_attempts: DEFAULT_MAX_ATTEMPTS, retry_delay: DEFAULT_RETRY_DELAY, sleep_fn: nil, &block) sleep_fn ||= method(:sleep) attempt = 0 begin attempt += 1 yield attempt rescue *TRANSIENT_ERRORS => e raise unless transient_error?(e) && attempt < max_attempts sleep_fn.call(retry_delay) retry end end