Class: DatastaxRails::RSolrClientWrapper

Inherits:
BlankSlate show all
Defined in:
lib/datastax_rails/rsolr_client_wrapper.rb

Overview

Wraps the RSolr Client class so that exceptions such as Connection Refused can be caught and a new server tried (if one is available)

Instance Method Summary collapse

Methods inherited from BlankSlate

find_hidden_method, hide, reveal

Constructor Details

#initialize(rsolr, model) ⇒ RSolrClientWrapper

Returns a new instance of RSolrClientWrapper.

Parameters:

  • rsolr (RSolr::Client)

    the initial RSolr client object to wrap



6
7
8
9
# File 'lib/datastax_rails/rsolr_client_wrapper.rb', line 6

def initialize(rsolr, model)
  @rsolr = rsolr
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/datastax_rails/rsolr_client_wrapper.rb', line 11

def method_missing(sym, *args, &block)
  if @rsolr.uri.host != DatastaxRails::Base.current_server
    @rsolr.uri.host = DatastaxRails::Base.current_server
    @rsolr = @model.establish_solr_connection
  end
  @rsolr.__send__(sym, *args, &block)
rescue Errno::ECONNREFUSED
  tries ||= 3
  tries -= 1
  if tries > 0
    # Force cassandra connection to roll
    DatastaxRails::Cql::Select.new(SchemaMigration, ['digest']).limit(1).execute
    retry
  else
    raise
  end
end