Class: DitoUtils::MethodRetry
- Inherits:
-
Object
- Object
- DitoUtils::MethodRetry
- Defined in:
- lib/dito_utils.rb
Instance Method Summary collapse
-
#initialize(sleep_time, retries = 10) ⇒ MethodRetry
constructor
A new instance of MethodRetry.
- #retry(error_class) ⇒ Object
Constructor Details
#initialize(sleep_time, retries = 10) ⇒ MethodRetry
Returns a new instance of MethodRetry.
5 6 7 8 9 |
# File 'lib/dito_utils.rb', line 5 def initialize(sleep_time, retries = 10) @sleep_time = sleep_time @retries = retries @error_count = 0 end |
Instance Method Details
#retry(error_class) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dito_utils.rb', line 11 def retry(error_class) while @error_count < @retries begin return yield rescue *error_class => e sleep(@sleep_time) increment_error_count raise e if last_try? end end end |