Module: SunspotOffline

Defined in:
lib/sunspot_offline.rb,
lib/sunspot_offline/version.rb,
lib/sunspot_offline/rsolr/client.rb,
lib/sunspot_offline/rails/railtie.rb,
lib/sunspot_offline/sidekiq/index_worker.rb,
lib/sunspot_offline/sidekiq/removal_worker.rb,
lib/sunspot_offline/sunspot/abstract_search.rb,
lib/sunspot_offline/sidekiq/current_job_middleware.rb

Defined Under Namespace

Modules: RSolr, Rails, Sidekiq, Sunspot

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.configurationObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sunspot_offline.rb', line 9

def configuration
  @configuration ||= OpenStruct.new(
    enabled: true,
    retry_delay: 1.hour,
    solr_error_callback: ->(_exception) {},
    filter_sidekiq_job_callback: ->(_job) { false }, # some Sidekiq jobs are allowed to fail and retry on their own
    index_job: Sidekiq::IndexWorker, # Sidekiq job which will handle index retries
    removal_job: Sidekiq::RemovalWorker, # Sidekiq job which will handle removal retries
    default_queue: 'default'
  )
end

.configureObject



21
22
23
24
25
26
27
28
# File 'lib/sunspot_offline.rb', line 21

def configure
  if block_given?
    yield(configuration)
    [SunspotOffline::Sidekiq::IndexWorker, SunspotOffline::Sidekiq::RemovalWorker].each do |worker|
      worker.sidekiq_options[:queue] = configuration.default_queue
    end
  end
end

.disabled?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/sunspot_offline.rb', line 38

def disabled?
  !configuration.enabled
end

.filter_sidekiq_job?(job_class_name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/sunspot_offline.rb', line 34

def filter_sidekiq_job?(job_class_name)
  configuration.filter_sidekiq_job_callback.call(job_class_name) if configuration.filter_sidekiq_job_callback
end

.on_solr_error(exception) ⇒ Object



30
31
32
# File 'lib/sunspot_offline.rb', line 30

def on_solr_error(exception)
  configuration.solr_error_callback.call(exception) if configuration.solr_error_callback
end