Class: Solr::Request::Runner

Inherits:
Object
  • Object
show all
Includes:
RunnerExtension, Support::UrlHelper
Defined in:
lib/solr/request/runner.rb,
lib/solr/testing.rb

Overview

TODO: Add documentation about request running

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::UrlHelper

build_request_url, core_name_from_url, core_url, current_core, solr_cloud_or_master_slave_url, solr_endpoint_from_url, solr_url

Constructor Details

#initialize(request:, node_selection_strategy: Solr::Request::DefaultNodeSelectionStrategy, solr_connection: Solr::Connection) ⇒ Runner

Returns a new instance of Runner.



22
23
24
25
26
27
28
29
# File 'lib/solr/request/runner.rb', line 22

def initialize(request:,
               node_selection_strategy: Solr::Request::DefaultNodeSelectionStrategy,
               solr_connection: Solr::Connection)
  @request = request
  @response_parser = response_parser
  @node_selection_strategy = node_selection_strategy
  @solr_connection = solr_connection
end

Instance Attribute Details

#node_selection_strategyObject (readonly)

Returns the value of attribute node_selection_strategy.



16
17
18
# File 'lib/solr/request/runner.rb', line 16

def node_selection_strategy
  @node_selection_strategy
end

#requestObject (readonly)

Returns the value of attribute request.



16
17
18
# File 'lib/solr/request/runner.rb', line 16

def request
  @request
end

#response_parserObject (readonly)

Returns the value of attribute response_parser.



16
17
18
# File 'lib/solr/request/runner.rb', line 16

def response_parser
  @response_parser
end

Class Method Details

.call(opts) ⇒ Object



18
19
20
# File 'lib/solr/request/runner.rb', line 18

def self.call(opts)
  new(**opts).call
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/solr/request/runner.rb', line 31

def call
  solr_url_errors = {}
  solr_urls.each do |node_url|
    request_url = build_request_url(url: node_url,
                                    path: request.path,
                                    url_params: request.url_params)
    begin
      raw_response = @solr_connection.call(url: request_url.to_s, method: request.method, body: request.body)
      solr_response = Solr::Response::Parser.call(raw_response)
      raise Solr::Errors::SolrQueryError, solr_response.error_message unless solr_response.ok?
      return solr_response
    rescue Faraday::ConnectionFailed, Faraday::TimeoutError, Errno::EADDRNOTAVAIL, Timeout::Error => e
      if Solr.master_slave_enabled?
        Solr.configuration.nodes_gray_list.add(node_url)
      end
      solr_url_errors[node_url] = "#{e.class.name} - #{e.message}"
      # Try next node
    end
  end

  raise Solr::Errors::SolrConnectionFailedError.new(solr_url_errors)
end