Created
March 14, 2012 09:45
-
-
Save ahawkins/2035427 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class RemoveRecordFromSolr | |
@queue = :high | |
def self.perform(klass, id) | |
klass.constantize.find(id).remove_from_index! | |
end | |
end |
This file contains hidden or 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
class IndexRecordInSolr | |
@queue = :high | |
def self.perform(klass, id) | |
klass.constantize.find(id).index! | |
end | |
end |
This file contains hidden or 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
class SolrObserver < ActiveRecord::Observer | |
observe Company, Customer, Todo, Deal, Message, PhoneCall | |
def after_save(record) | |
return if ENV['POPULATING'] | |
Resque.enqueue IndexRecordInSolr, record.class.to_s, record.id | |
end | |
def before_destroy(record) | |
return if ENV['POPULATING'] | |
Resque.enqueue RemoveRecordFromSolr, record.class.to_s, record.id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment