Skip to content

Instantly share code, notes, and snippets.

View lleirborras's full-sized avatar
💭
Not much

Lleïr Borràs Metje lleirborras

💭
Not much
View GitHub Profile
# 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])
# 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
#
# 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
#