Last active
August 29, 2015 14:06
-
-
Save ColinDKelley/5194bb51b2c6b234cc26 to your computer and use it in GitHub Desktop.
retry_on_exception
This file contains hidden or 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
result = | |
retry_on_exception(Timeout::Error, total_tries: 2) do | |
http_fe.post(...) | |
end |
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes! Can we add this to the exception handling gem?