Sha256: 6b37e62d608cc2872e134f9fa31c3a2f9efdcb25c5ebd404c8035a2c6b397ca8
Contents?: true
Size: 961 Bytes
Versions: 7
Compression:
Stored size: 961 Bytes
Contents
# frozen_string_literal: true module Mihari module Mixins # # Retriable mixin # module Retriable DEFAULT_ON = [ Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL::SSLError, Timeout::Error, RetryableError, NetworkError, TimeoutError, StatusCodeError ].freeze # # Retry on error # # @param [Integer] times # @param [Integer] interval # @param [Boolean] exponential_backoff # @param [Array<StandardError>] on # def retry_on_error(times: 3, interval: 5, exponential_backoff: true, on: DEFAULT_ON) try = 0 begin try += 1 yield rescue *on => e sleep_seconds = exponential_backoff ? interval * (2**(try - 1)) : interval sleep sleep_seconds retry if try < times raise e end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems