Class: PactBroker::Client::Retry
- Inherits:
-
Object
- Object
- PactBroker::Client::Retry
- Defined in:
- lib/pact_broker/client/retry.rb
Defined Under Namespace
Classes: RescuableError
Class Method Summary collapse
- .sleep(seconds) ⇒ Object
- .until_truthy_or_max_times(options = {}) ⇒ Object
- .while_error(options = {}) ⇒ Object
Class Method Details
.sleep(seconds) ⇒ Object
60 61 62 |
# File 'lib/pact_broker/client/retry.rb', line 60 def self.sleep seconds Kernel.sleep seconds end |
.until_truthy_or_max_times(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pact_broker/client/retry.rb', line 32 def self.until_truthy_or_max_times = {} max_tries = .fetch(:times, 3) tries = 0 verbose = [:verbose] sleep_interval = .fetch(:sleep, 5) sleep(sleep_interval) if [:sleep_first] while true begin result = yield return result if max_tries < 2 if [:condition] condition_result = [:condition].call(result) return result if condition_result else return result if result end tries += 1 return result if max_tries == tries sleep sleep_interval rescue RescuableError => e tries += 1 $stderr.puts "ERROR: Error making request - #{e.class} #{e.} #{e.backtrace.find{|l| l.include?('pact_broker-client')}}, attempt #{tries} of #{max_tries}" raise e if max_tries == tries sleep sleep_interval end end end |
.while_error(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pact_broker/client/retry.rb', line 17 def self.while_error = {} max_tries = .fetch(:times, 3) tries = 0 while true begin return yield rescue RescuableError => e tries += 1 $stderr.puts "Error making request - #{e.class} #{e.} #{e.backtrace.find{|l| l.include?('pact_broker-client')}}, attempt #{tries} of #{max_tries}" raise e if max_tries == tries sleep .fetch(:sleep, 5) end end end |