Skip to content

Instantly share code, notes, and snippets.

@aeden
Created December 21, 2010 15:30
Show Gist options
  • Save aeden/750063 to your computer and use it in GitHub Desktop.
Save aeden/750063 to your computer and use it in GitHub Desktop.
A simple class for retrying a block on an exception.
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
@aeden
Copy link
Author

aeden commented Dec 21, 2010

Example for using it here: https://gist.github.com/750065

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