Module: ZeevexReliability::Retryable
- Defined in:
- lib/zeevex_reliability/retryable.rb
Class Method Summary collapse
-
.retryable(options = {}, &block) ⇒ Object
Options: * :tries - Number of retries to perform.
Class Method Details
.retryable(options = {}, &block) ⇒ Object
Options:
-
:tries - Number of retries to perform. Defaults to 3.
-
:on - The Exception on which a retry will be performed.
Defaults to StandardError
If the final attempts also receives an exception, that exception will be raised.
Example
retryable(:tries => 1, :on => OpenURI::HTTPError) do
# your code here
end
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zeevex_reliability/retryable.rb', line 17 def self.retryable( = {}, &block) opts = { :tries => 3, :on => StandardError }.merge() retry_exception, retries = opts[:on], opts[:tries] begin return yield rescue retry_exception if (retries -= 1) > 0 retry else raise end end end |