Sunspot Offline
Simple fail over method into your sunspot_rails + sidekiq setup
Why?
Because Solr sometimes fails, it happens. It might be a maintenance work you have to do or just Out-Of-Memory problems. If you are running search-sensitive Rails app, you have to deal with it. This gem was developed to postpone your index tasks automatically into a sidekiq queue if Solr engine becomes unavailable
Rails Support
Rails 5.0 and higher
Installation
Add this line to your application's Gemfile:
gem 'sunspot_offline'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sunspot_offline
Configuration
By default gem is configured to use built-in workers which will auto-retry indexing in 1 hour is Solr goes offline. This all is configurable, preferable via initializer:
# config/initializers/sunspot_offline.rb
SunspotOffline.configure do |config|
config.retry_delay = 1.hour
end
Valid configuration options
Option | Type | Default value | |
---|---|---|---|
index_job | Class | bundled worker class | Sidekiq worker which will retry saving new documents to Solr. Accepts 2 arguments: ActiveRecord class and id (numbers, arrays, and hashes are all valid for this argument) |
removal_job | Class | bundled worker class | Sidekiq worker which will retry removing existing documents from Solr. Accepts same set of arguments as index_job . |
retry_delay | Duration | 1 hour | Delay in which sidekiq will attempt to run index_job or removal_job
|
default_queue | String | 'default' | Sidekiq's named queue to use |
solr_error_callback | Proc(exception) | nil |
A proc which will be executed if Solr is detected to be offline |
filter_sidekiq_job_callback | Proc(job_class) | nil |
Since some Solr indexing might be happening inside yours sidekiq jobs they dont need to have a custom fail over, sidekiq is able to retry failures by itself. Using this proc you can configure which jobs could be filtered out:->(job_name) { job_name == 'MySolrIndexJob' } . In this sample MySolrIndexJob wont be applied for a fail over |
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Run tests (
bundle exec appraisal install && bundle exec appraisal rake
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
The gem is available as open source under the terms of the MIT License.