Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Created March 14, 2012 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahawkins/2035427 to your computer and use it in GitHub Desktop.
Save ahawkins/2035427 to your computer and use it in GitHub Desktop.
class RemoveRecordFromSolr
@queue = :high
def self.perform(klass, id)
klass.constantize.find(id).remove_from_index!
end
end
class IndexRecordInSolr
@queue = :high
def self.perform(klass, id)
klass.constantize.find(id).index!
end
end
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