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 allows to use a numeric or a lambda | |
def retry_upto(max_retries = 1, options = {}) | |
begin | |
return yield if ((max_retries -= 1) > 0) | |
rescue (options[:rescue_only] || Exception) | |
options[:wait] = if options[:patience].is_a?(Numeric) | |
options[:wait] * options[:patience] | |
else | |
options[:patience].call(options[:wait]) |
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
# Ruby `retry` with steroids: | |
# | |
# - retry up to 5 times without waiting between them and retrying after any exception | |
# | |
# retry_upto(5) do ... end | |
# | |
# - retry up to 5 times, waiting 2 seconds between retries and retrying after any exception | |
# | |
# retry_upto(5, :wait => 2) do ... 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
# Ruby `retry` with steroids: | |
# | |
# - retry up to 5 times without waiting between them and retrying after any exception | |
# | |
# retry_upto(5) do ... end | |
# | |
# - retry up to 5 times, waiting 2 seconds between retries and retrying after any exception | |
# | |
# retry_upto(5, :wait => 2) do ... end | |
# |