Created
December 21, 2010 15:30
-
-
Save aeden/750063 to your computer and use it in GitHub Desktop.
A simple class for retrying a block on an 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
class Retryable | |
def self.retry_on(exception, times=2, handler=nil) | |
retry_times = times || 2 | |
begin | |
yield | |
rescue exception => e | |
handler.call if handler | |
retry if (retry_times -= 1) > 0 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example for using it here: https://gist.github.com/750065