Sha256: 1a764d6659437e6e79241bc274aa195b9c817f1f45ba7e990cc2134c2fc82165
Contents?: true
Size: 1002 Bytes
Versions: 5
Compression:
Stored size: 1002 Bytes
Contents
# frozen_string_literal: true module Mihari module Concerns # # Retriable concern # module Retriable extend ActiveSupport::Concern 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
5 entries across 5 versions & 1 rubygems