Class: Unity::Utils::Retrier
- Inherits:
-
Object
- Object
- Unity::Utils::Retrier
- Defined in:
- lib/unity/utils/retrier.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#sleep_factor ⇒ Object
readonly
Returns the value of attribute sleep_factor.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(errors = nil, max_retries = 5, sleep_factor = 0.3) ⇒ Retrier
constructor
A new instance of Retrier.
Constructor Details
#initialize(errors = nil, max_retries = 5, sleep_factor = 0.3) ⇒ Retrier
Returns a new instance of Retrier.
12 13 14 15 16 |
# File 'lib/unity/utils/retrier.rb', line 12 def initialize(errors = nil, max_retries = 5, sleep_factor = 0.3) @errors = errors || [StandardError] @max_retries = max_retries @sleep_factor = sleep_factor end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/unity/utils/retrier.rb', line 6 def errors @errors end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
6 7 8 |
# File 'lib/unity/utils/retrier.rb', line 6 def max_retries @max_retries end |
#sleep_factor ⇒ Object (readonly)
Returns the value of attribute sleep_factor.
6 7 8 |
# File 'lib/unity/utils/retrier.rb', line 6 def sleep_factor @sleep_factor end |
Class Method Details
.call ⇒ Object
8 9 10 |
# File 'lib/unity/utils/retrier.rb', line 8 def self.call new.call(&Proc.new) if block_given? end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/unity/utils/retrier.rb', line 18 def call return unless block_given? retries = 0 begin yield rescue *errors => e retries += 1 raise e if retries > max_retries sleep_on(retries) retry end end |