Module: Itrp::SendWithRetries

Defined in:
lib/itrp/client.rb

Instance Method Summary collapse

Instance Method Details

#_send(request, domain = @domain, port = @port, ssl = @ssl) ⇒ Object

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



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# 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