lib/elasticsearch/transport/transport/base.rb in elasticsearch-transport-7.8.1 vs lib/elasticsearch/transport/transport/base.rb in elasticsearch-transport-7.9.0.pre
- old
+ new
@@ -45,11 +45,11 @@
# @option arguments [Array] :hosts An Array of normalized hosts information
# @option arguments [Array] :options A Hash with options (usually passed by {Client})
#
# @see Client#initialize
#
- def initialize(arguments={}, &block)
+ def initialize(arguments = {}, &block)
@state_mutex = Mutex.new
@hosts = arguments[:hosts] || []
@options = arguments[:options] || {}
@options[:http] ||= {}
@@ -232,13 +232,13 @@
#
# @api private
def __full_url(host)
url = "#{host[:protocol]}://"
url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user]
- url += "#{host[:host]}"
+ url += host[:host]
url += ":#{host[:port]}" if host[:port]
- url += "#{host[:path]}" if host[:path]
+ url += host[:path] if host[:path]
url
end
# Performs a request to Elasticsearch, while handling logging, tracing, marking dead connections,
# retrying the request and reloading the connections.
@@ -256,12 +256,13 @@
# @return [Response]
# @raise [NoMethodError] If no block is passed
# @raise [ServerError] If request failed on server
# @raise [Error] If no connection is available
#
- def perform_request(method, path, params={}, body=nil, headers=nil, opts={}, &block)
- raise NoMethodError, "Implement this method in your transport class" unless block_given?
+ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {}, &block)
+ raise NoMethodError, 'Implement this method in your transport class' unless block_given?
+
start = Time.now
tries = 0
reload_on_failure = opts.fetch(:reload_on_failure, @options[:reload_on_failure])
max_retries = if opts.key?(:retry_on_failure)
@@ -274,18 +275,18 @@
ignore = Array(params.delete(:ignore)).compact.map { |s| s.to_i }
begin
tries += 1
- connection = get_connection or raise Error.new("Cannot get new connection from pool.")
+ connection = get_connection or raise Error.new('Cannot get new connection from pool.')
if connection.connection.respond_to?(:params) && connection.connection.params.respond_to?(:to_hash)
params = connection.connection.params.merge(params.to_hash)
end
- url = connection.full_url(path, params)
+ url = connection.full_url(path, params)
- response = block.call(connection, url)
+ response = block.call(connection, url)
connection.healthy! if connection.failures > 0
# Raise an exception so we can catch it for `retry_on_status`
__raise_transport_error(response) if response.status.to_i >= 300 && @retry_on_status.include?(response.status.to_i)