class EsClient::Client
Constants
- HTTP_VERBS
- RETRY_TIMES
- SUCCESS_HTTP_CODES
Public Class Methods
new(host, options)
click to toggle source
# File lib/es_client/client.rb, line 9 def initialize(host, options) @host = host @options = options end
Public Instance Methods
http()
click to toggle source
# File lib/es_client/client.rb, line 49 def http @http ||= Excon.new(@host, @options) end
log(message, level=:info)
click to toggle source
# File lib/es_client/client.rb, line 57 def log(message, level=:info) EsClient.logger.try!(level, message) end
reconnect!()
click to toggle source
# File lib/es_client/client.rb, line 53 def reconnect! @http = nil end
request(options)
click to toggle source
# File lib/es_client/client.rb, line 27 def request(options) retry_times = 0 begin raw_response = http.request(options) response = ::EsClient::Response.new(raw_response.body, raw_response.status, raw_response.headers) EsClient.logger.request(http, response, options) if EsClient.logger.try!(:debug?) response rescue Excon::Errors::SocketError => e if retry_times >= RETRY_TIMES EsClient.logger.exception(e, http, options) if EsClient.logger raise end retry_times += 1 EsClient.logger.info "[#{retry_times}] Try reconnect to #{@host}" reconnect! retry rescue Excon::Errors::BadRequest => e EsClient.logger.exception(e, http, options.merge(response: e.response.body)) if EsClient.logger raise end end