Sha256: 4c5a1fb3e0cab50831e237714431f7eeacff7f1fb61f519e0ad3407dcd31c637

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

# -*- coding: utf-8 -*-
module XapianDb
  module IndexWriters
    # 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
    class SidekiqWorker

      extend XapianDb::Utilities

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

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

      class << self
        def queue
          XapianDb::Config.sidekiq_queue
        end

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

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
xapian_db-1.3.5.4 lib/xapian_db/index_writers/sidekiq_worker.rb
xapian_db-1.3.5.3 lib/xapian_db/index_writers/sidekiq_worker.rb
xapian_db-1.3.5.2 lib/xapian_db/index_writers/sidekiq_worker.rb
xapian_db-1.3.5.1 lib/xapian_db/index_writers/sidekiq_worker.rb
xapian_db-1.3.5 lib/xapian_db/index_writers/sidekiq_worker.rb
xapian_db-1.3.4 lib/xapian_db/index_writers/sidekiq_worker.rb