Sha256: aa23d8cb090ecb111309b35840c05289a6d2d191e7e551cf68f9adc172fa3a17

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

# -*- coding: utf-8 -*-
module XapianDb
  module IndexWriters
    # Worker to update the Xapian index; the worker will be called by resque
    # and uses the DirectWriter to do the real work
    # @author Michael Stämpfli
    class ResqueWorker

      extend XapianDb::Utilities

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

      class << self
        def queue
          XapianDb::Config.resque_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, true, changed_attrs: options[:changed_attrs]
        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

13 entries across 13 versions & 1 rubygems

Version Path
xapian_db-1.3.15 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.14 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.13 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.12 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.11 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.10 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.9 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.8 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.7.4 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.7.3 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.7.2 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.7.1 lib/xapian_db/index_writers/resque_worker.rb
xapian_db-1.3.7 lib/xapian_db/index_writers/resque_worker.rb