Created
July 9, 2010 18:41
-
-
Save leosoto/469846 to your computer and use it in GitHub Desktop.
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
def retrying(attempts, options = {}) | |
exception_class = options[:when] || Exception | |
sleep_time = options[:sleep] || 0.seconds | |
last_exception = nil | |
attempts.each do | |
begin | |
return yield | |
rescue exception_class => last_exception | |
Kernel.sleep sleep_time.to_f | |
end | |
end | |
raise last_exception | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment