Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

master/slave failover support for sunspot_rails

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 sunspot-rails-failover.gemspec
README.md

sunspot-rails-failover

Sunspot comes with MasterSlaveSessionProxy that does the following:

This session proxy implementation allows Sunspot to be used with a master/slave Solr deployment. All write methods are delegated to a master session, and read methods are delegated to a slave session.

What this simple gem does is provide failover support if the slave session goes down. Reads and writes are called on the master session.

Setup

Your config/sunspot.yml file should look something like this:

development:
  master_solr:
    host: ...
    port: ...
  solr:
    host: ...

NOTE: You do not have to have a master session. If a master session is not detected, sunspot-rails-failover will default to what sunspot_rails provides.

Next, add an initializer (maybe initializers/sunspot.rb) with the following code:

Sunspot::Rails::Failover.setup

Exception handling

sunspot-rails-failover supports exception handling for committing and searching. Currently, it will use Hoptoad by default if it is installed. The exception is passed to HoptoadNotifier.notify.

You can also use a custom class/module to customize how you want to handle the exception. In initializers/sunspot.rb:

module MyExceptionHandler
  def self.handle(exception)
    Notifier.deliver_exception_message(exception)
  end
end

Sunspot::Rails::Failover.exception_handler = MyExceptionHandler
Sunspot::Rails::Failover.setup

License

sunspot-rails-failover is released under the MIT license. See LICENSE for details.

Copyright

Copyright (c) 2011 Justin Ko

Something went wrong with that request. Please try again.