forked from pact-foundation/pact-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add retries to verification publishing
- Loading branch information
1 parent
8a0a73f
commit 6620165
Showing
3 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters