Module: Dickburt::Retryable
- Included in:
- Server
- Defined in:
- lib/dickburt/retryable.rb
Instance Method Summary collapse
-
#retryable(options = {}, &block) ⇒ Object
Options: * :tries - Number of retries to perform.
Instance Method Details
#retryable(options = {}, &block) ⇒ Object
Options:
-
:tries - Number of retries to perform. Defaults to 1.
-
:on - The Exception on which a retry will be performed. Defaults to Exception, which retries on any Exception.
Example
retryable(:tries => 1, :on => OpenURI::HTTPError) do
# your code here
end
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dickburt/retryable.rb', line 13 def retryable( = {}, &block) opts = { :tries => 1, :on => Exception }.merge() retry_exception, retries = opts[:on], opts[:tries] begin return yield rescue retry_exception puts "="*45 puts "#{retry_exception} raised. Retrying #{retries - 1} more times" puts "="*45 retry if (retries -= 1) > 0 end yield end |