Skip to content

Instantly share code, notes, and snippets.

@ColinDKelley
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ColinDKelley/5194bb51b2c6b234cc26 to your computer and use it in GitHub Desktop.
Save ColinDKelley/5194bb51b2c6b234cc26 to your computer and use it in GitHub Desktop.
retry_on_exception
result =
retry_on_exception(Timeout::Error, total_tries: 2) do
http_fe.post(...)
end
def retry_on_exception(exception_classes, total_tries:)
# retryable
(total_tries - 1).times do
begin
return yield
rescue *Array(exception_class)
# try again
end
end
# one final try
yield
end
@primiti
Copy link

primiti commented Sep 15, 2014

Yes! Can we add this to the exception handling gem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment