Sha256: 632e5767d074baa9ae9a35507efa1279a2aee83f20daf9fdd9365a159ce3cd91

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

# This writer puts reindex requests into a stalker queue. If you want
# to use this writer, you must install beanstalkd and the stalker gem.
# This writer can only be used inside a Rails app.
# See https://github.com/adamwiggins/stalker for more info
# @author Gernot Kogler

require 'beanstalk-client'

module XapianDb
  module IndexWriters

    class BeanstalkWriter

      class << self

        # Update an object in the index
        # @param [Object] obj An instance of a class with a blueprint configuration
        def index(obj)
          beanstalk.put({:task => "index_task", :class => obj.class.name, :id => obj.id}.to_yaml)
        end

        # Remove an object from the index
        # @param [Object] obj An instance of a class with a blueprint configuration
        def unindex(obj)
          beanstalk.put({:task => "unindex_task", :class => obj.class.name, :id => obj.id}.to_yaml)
        end

        # Reindex all objects of a given class
        # @param [Class] klass The class to reindex
        def reindex_class(klass, options={})
          beanstalk.put({:task => "reindex_class_task", :class => klass.name}.to_yaml)
        end

        private

        def beanstalk
          @beanstalk ||= Beanstalk::Pool.new([XapianDb::Config.beanstalk_daemon_url])
        end

      end

    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
xapian_db-0.5.13 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.12 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.11 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.10 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.9 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.8 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.7 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.6 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.5 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.4 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.3 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.2 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.1 lib/xapian_db/index_writers/beanstalk_writer.rb
xapian_db-0.5.0 lib/xapian_db/index_writers/beanstalk_writer.rb