module Itrp::SendWithRetries

Public Instance Methods

_send(request, domain = @domain, port = @port, ssl = @ssl) click to toggle source

Wraps the _send method with retries when the server does not respond, see initialize option :retries

Calls superclass method
# File lib/itrp/client.rb, line 327
def _send(request, domain = @domain, port = @port, ssl = @ssl)
  return super(request, domain, port, ssl) unless option(:max_retry_time) > 0
  retries = 0
  sleep_time = 1
  now = Time.now
  timed_out = false
  begin
    _response = super(request, domain, port, ssl)
    # throttling is handled separately
    if !_response.success? && !_response.throttled?
      sleep_time *= 2
      if (Time.now - now + sleep_time) < option(:max_retry_time)
        @logger.warn { "Request failed, retry ##{retries += 1} in #{sleep_time} seconds: #{_response.message}" }
        sleep(sleep_time)
      else
        timed_out = true
      end
    end
  end while !_response.success? && !_response.throttled? && !timed_out
  _response
end