Created
February 10, 2012 22:20
-
-
Save nz/1793541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sunspot_ext/resque_session_proxy' | |
require 'sunspot_ext/resque_index_job' | |
Sunspot.session = Sunspot::ResqueSessionProxy.new(Sunspot.session) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sunspot | |
class IndexJob | |
@queue = :sunspot_indexer | |
def self.perform(*args) | |
objects = [] | |
args.each_slice(2) do |(clazz, id)| | |
object = clazz.constantize.find_by_id(id) | |
# don't blow up if the object no longer exists in the db | |
if object | |
objects << object | |
end | |
end | |
Sunspot.session.original_session.index(*objects) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sunspot | |
class ResqueSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy | |
attr_reader :original_session | |
delegate :config, :delete_dirty?, :dirty?, | |
:new_search, :search, | |
:new_more_like_this, :more_like_this, | |
:remove, :remove!, | |
:remove_by_id, :remove_by_id!, | |
:remove_all, :remove_all!, | |
:batch, :commit, :commit_if_delete_dirty, :commit_if_dirty, | |
:index!, | |
:to => :session | |
def initialize(session) | |
@original_session = session | |
end | |
alias_method :session, :original_session | |
def index(*objects) | |
args = [] | |
objects.flatten.compact.each do |object| | |
args << object.class.name << object.id | |
end | |
Resque.enqueue(Sunspot::IndexJob, *args) unless args.empty? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic. Got this running on Heroku very quickly.