module Take2::InstanceMethods

Public Instance Methods

call_api_with_retry(options = {}, &block) click to toggle source

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
    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
# File lib/take2.rb, line 62
def call_api_with_retry(options = {}, &block)
  self.class.call_api_with_retry(options, &block)
end
Also aliased as: with_retry
with_retry(options = {}, &block)
Alias for: call_api_with_retry