Sha256: dfb89297b933e72dcf05a8df9f322e3c2a5891457aea4690a95a1db33e56a66e

Contents?: true

Size: 788 Bytes

Versions: 6

Compression:

Stored size: 788 Bytes

Contents

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

6 entries across 6 versions & 1 rubygems

Version Path
pact-1.28.0 lib/pact/retry.rb
pact-1.28.0.rc1 lib/pact/retry.rb
pact-1.27.0 lib/pact/retry.rb
pact-1.26.0 lib/pact/retry.rb
pact-1.25.0 lib/pact/retry.rb
pact-1.24.0 lib/pact/retry.rb