Module: Kernel
- Defined in:
- lib/testjour.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
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/testjour.rb', line 18 def retryable( = {}, &block) opts = { :tries => 1, :on => Exception }.merge() retry_exception, retries = opts[:on], opts[:tries] begin return yield rescue retry_exception retry if (retries -= 1) > 0 end yield end |