Class: XapianDb::IndexWriters::SidekiqWorker

Inherits:
Object
  • Object
show all
Extended by:
Utilities
Defined in:
lib/xapian_db/index_writers/sidekiq_worker.rb

Overview

Worker to update the Xapian index; the worker will be called by sidekiq and uses the DirectWriter to do the real work

Author:

  • Michael Stämpfli and John Bradley

Constant Summary collapse

APPROVED_TASKS =
[:index, :delete_doc, :reindex_class]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

assert_valid_keys, camelize, constantize

Class Method Details

.delete_doc(options) ⇒ Object



32
33
34
# File 'lib/xapian_db/index_writers/sidekiq_worker.rb', line 32

def delete_doc(options)
  DirectWriter.delete_doc_with options['xapian_id']
end

.index(options) ⇒ Object



26
27
28
29
30
# File 'lib/xapian_db/index_writers/sidekiq_worker.rb', line 26

def index(options)
  klass = constantize options['class']
  obj   = klass.respond_to?('get') ? klass.get(options['id']) : klass.find(options['id'])
  DirectWriter.index obj, true, changed_attrs: options[:changed_attrs]
end

.perform(task, options) ⇒ Object



22
23
24
# File 'lib/xapian_db/index_writers/sidekiq_worker.rb', line 22

def perform(task, options)
  send(task, options) if APPROVED_TASKS.include?(task.to_sym)
end

.queueObject



18
19
20
# File 'lib/xapian_db/index_writers/sidekiq_worker.rb', line 18

def queue
  XapianDb::Config.sidekiq_queue
end

.reindex_class(options) ⇒ Object



36
37
38
39
# File 'lib/xapian_db/index_writers/sidekiq_worker.rb', line 36

def reindex_class(options)
  klass = constantize options['class']
  DirectWriter.reindex_class klass, :verbose => false
end

Instance Method Details

#perform(task, options) ⇒ Object



13
14
15
# File 'lib/xapian_db/index_writers/sidekiq_worker.rb', line 13

def perform(task, options)
  self.class.send(task, options) if APPROVED_TASKS.include?(task.to_sym)
end