Sha256: d5f00524331f84226b672c79dbbd4d2515f82f628715896c8aae1b9b99de02cd

Contents?: true

Size: 719 Bytes

Versions: 23

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

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

      #
      # Retry on error
      #
      # @param [Integer] times
      # @param [Integer] interval
      # @param [Array<StandardError>] on
      #
      # @return [nil]
      #
      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
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mihari-5.1.0 lib/mihari/mixins/retriable.rb
mihari-5.0.1 lib/mihari/mixins/retriable.rb
mihari-5.0.0 lib/mihari/mixins/retriable.rb
mihari-4.12.0 lib/mihari/mixins/retriable.rb
mihari-4.11.0 lib/mihari/mixins/retriable.rb
mihari-4.10.0 lib/mihari/mixins/retriable.rb
mihari-4.9.0 lib/mihari/mixins/retriable.rb
mihari-4.8.0 lib/mihari/mixins/retriable.rb
mihari-4.7.4 lib/mihari/mixins/retriable.rb
mihari-4.7.3 lib/mihari/mixins/retriable.rb
mihari-4.7.2 lib/mihari/mixins/retriable.rb
mihari-4.7.1 lib/mihari/mixins/retriable.rb
mihari-4.7.0 lib/mihari/mixins/retriable.rb
mihari-4.6.1 lib/mihari/mixins/retriable.rb
mihari-4.6.0 lib/mihari/mixins/retriable.rb
mihari-4.5.3 lib/mihari/mixins/retriable.rb
mihari-4.5.2 lib/mihari/mixins/retriable.rb
mihari-4.5.1 lib/mihari/mixins/retriable.rb
mihari-4.5.0 lib/mihari/mixins/retriable.rb
mihari-4.4.1 lib/mihari/mixins/retriable.rb