Class: Wrappi::Executer::Retryer
- Inherits:
-
Object
- Object
- Wrappi::Executer::Retryer
- Defined in:
- lib/wrappi/executer/retryer.rb
Defined Under Namespace
Classes: RetryError
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(endpoint) ⇒ Retryer
constructor
A new instance of Retryer.
- #retry? ⇒ Boolean
- #retry_if ⇒ Object
- #retry_options ⇒ Object
Constructor Details
#initialize(endpoint) ⇒ Retryer
Returns a new instance of Retryer.
6 7 8 |
# File 'lib/wrappi/executer/retryer.rb', line 6 def initialize(endpoint) @endpoint = endpoint end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/wrappi/executer/retryer.rb', line 5 def endpoint @endpoint end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/wrappi/executer/retryer.rb', line 10 def call if retry? Retryable.retryable() do res = yield raise RetryError if retry_if.call(res, endpoint) res end else yield end end |
#retry? ⇒ Boolean
37 38 39 |
# File 'lib/wrappi/executer/retryer.rb', line 37 def retry? !!endpoint.retry_if end |
#retry_if ⇒ Object
41 42 43 |
# File 'lib/wrappi/executer/retryer.rb', line 41 def retry_if endpoint.retry_if end |
#retry_options ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wrappi/executer/retryer.rb', line 22 def default = { tries: 3, on: [RetryError] } if endpoint. end_opts = endpoint..dup {}.tap do |h| h[:tries] = end_opts[:tries] || default[:tries] if on = end_opts.delete(:on) h[:on] = default[:on] + Fusu::Array.wrap(on) end end.merge(end_opts) else default end end |