Module: Take2::InstanceMethods
- Defined in:
- lib/take2.rb
Instance Method Summary collapse
-
#call_api_with_retry(options = {}, &block) ⇒ Object
(also: #with_retry)
Yields a block and retries on retriable errors n times.
Instance Method Details
#call_api_with_retry(options = {}, &block) ⇒ Object Also known as: with_retry
Yields a block and retries on retriable errors n times. The raised error could be the defined retriable or it child.
Example:
class PizzaService
include Take2
number_of_retries 3
retriable_errors Net::HTTPRetriableError
retriable_condition proc { |error| response_status(error.response) < 500 }
on_retry proc { |error, tries|
puts "#{self.name} - Retrying.. #{tries} of #{self.retriable_configuration[:retries]} (#{error})"
}
backoff_strategy type: :exponential, start: 3
def give_me_food
call_api_with_retry do
# Some logic that might raise..
# If it will raise retriable, magic happens.
# If not the original error re raised
end
end
end
59 60 61 |
# File 'lib/take2.rb', line 59 def call_api_with_retry( = {}, &block) self.class.call_api_with_retry(, &block) end |