Module: Retrying
- Defined in:
- lib/retrying.rb,
lib/retrying/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
Instance Method Details
#retrying(options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/retrying.rb', line 4 def ( = {}, &block) = { :on => StandardError, :tries => 2, :sleep => 0 }.merge() exceptions = Array([:on]) attempts = 0 begin yield rescue *exceptions => ex attempts += 1 raise if attempts >= [:tries] sleep([:sleep]) if [:sleep] > 0 retry end end |