Class: PactBroker::Client::Retry

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/client/retry.rb

Class Method Summary collapse

Class Method Details

.sleep(options) ⇒ Object



20
21
22
# File 'lib/pact_broker/client/retry.rb', line 20

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

.until_true(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pact_broker/client/retry.rb', line 5

def self.until_true options = {}
  max_tries = options.fetch(:times, 3)
  tries = 0
  while true
    begin
      return yield
    rescue StandardError => e
      tries += 1
      $stderr.puts "Error publishing pact - #{e.message}, attempt #{tries} of #{max_tries}"
      sleep options
      raise e if max_tries == tries
    end
  end
end