Sha256: 550ecbf2b9b7ccedcd38ea3966cf701c2eb4d3e4af6469bef2c3197f209cf6d1

Contents?: true

Size: 811 Bytes

Versions: 64

Compression:

Stored size: 811 Bytes

Contents

require 'pact/errors'

module Pact
  class Retry
    class RescuableError
      UNRESCUEABLE = [Pact::Error]

      def self.===(e)
        case e
          when *UNRESCUEABLE then
            false
          else
            true
        end
      end
    end

    def self.until_true options = {}
      max_tries = options.fetch(:times, 3)
      tries = 0
      while true
        begin
          return yield
        rescue RescuableError => e
          tries += 1
          $stderr.puts "Error making request - #{e.class} #{e.message} #{e.backtrace.find {|l| l.include?('pact_provider')}}, attempt #{tries} of #{max_tries}"
          raise e if max_tries == tries
          sleep options
        end
      end
    end

    def self.sleep options
      Kernel.sleep options.fetch(:sleep, 5)
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
pact-1.66.1 lib/pact/retry.rb
pact-1.66.0 lib/pact/retry.rb
pact-1.65.3 lib/pact/retry.rb
pact-1.65.2 lib/pact/retry.rb
pact-1.65.1 lib/pact/retry.rb
pact-1.65.0 lib/pact/retry.rb
pact-1.64.0 lib/pact/retry.rb
pact-1.63.0 lib/pact/retry.rb
pact-1.62.0 lib/pact/retry.rb
pact-1.61.0 lib/pact/retry.rb
pact-1.60.0 lib/pact/retry.rb
pact-1.59.0 lib/pact/retry.rb
pact-1.58.0 lib/pact/retry.rb
pact-1.57.0 lib/pact/retry.rb
pact-1.56.0 lib/pact/retry.rb
pact-1.55.7 lib/pact/retry.rb
pact-1.55.6 lib/pact/retry.rb
pact-1.55.5 lib/pact/retry.rb
pact-1.55.4 lib/pact/retry.rb
pact-1.55.3 lib/pact/retry.rb