Top Level Namespace
Defined Under Namespace
Classes: Enumerator
Instance Method Summary collapse
-
#retry_upto(max_retries = 1, opts = {}) ⇒ Object
See README.md for usage explanations.
Instance Method Details
#retry_upto(max_retries = 1, opts = {}) ⇒ Object
See README.md for usage explanations
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/retry_upto.rb', line 3 def retry_upto(max_retries = 1, opts = {}) yield rescue *(opts[:rescue] || Exception) attempt = attempt ? attempt+1 : 1 raise if (attempt == max_retries) if interval = opts[:interval] secs = interval.respond_to?(:call) ? interval.call(attempt) : interval sleep(secs) end retry end |