Class: ExpRetry
- Inherits:
-
Object
- Object
- ExpRetry
- Defined in:
- lib/exp_retry.rb
Overview
Exponential backoff retry wrapper
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#tried ⇒ Object
readonly
Returns the value of attribute tried.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(retries: 3, exception: StandardError, wait: 1000, verbose: false) ⇒ ExpRetry
constructor
A new instance of ExpRetry.
Constructor Details
#initialize(retries: 3, exception: StandardError, wait: 1000, verbose: false) ⇒ ExpRetry
Returns a new instance of ExpRetry.
12 13 14 15 16 17 18 |
# File 'lib/exp_retry.rb', line 12 def initialize(retries: 3, exception: StandardError, wait: 1000, verbose: false) @retries = retries @tried = 0 @exception = exception @verbose = verbose @wait = wait end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
6 7 8 |
# File 'lib/exp_retry.rb', line 6 def exception @exception end |
#retries ⇒ Object
Returns the value of attribute retries.
5 6 7 |
# File 'lib/exp_retry.rb', line 5 def retries @retries end |
#tried ⇒ Object (readonly)
Returns the value of attribute tried.
6 7 8 |
# File 'lib/exp_retry.rb', line 6 def tried @tried end |
Class Method Details
.for(retries: 3, exception: StandardError, verbose: false) ⇒ Object
8 9 10 |
# File 'lib/exp_retry.rb', line 8 def self.for(retries: 3, exception: StandardError, verbose: false) new(retries: retries, exception: exception, verbose: verbose).call { yield } end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 |
# File 'lib/exp_retry.rb', line 20 def call yield if block_given? rescue *@exception => e check(e) retry end |