Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from bbhoss/sidekiq_indexing.rb
Created April 2, 2014 21:34
Show Gist options
  • Save kivanio/9943651 to your computer and use it in GitHub Desktop.
Save kivanio/9943651 to your computer and use it in GitHub Desktop.
module SidekiqIndexing
module SearchableOverride
extend ActiveSupport::Concern
module InstanceOverrides
def solr_index
SunspotIndexer.perform_async(self.class.to_s, self.id)
end
end
module ClassMethods
def searchable(*args, &blk)
super
include InstanceOverrides
end
end
end
class Railtie < ::Rails::Railtie
initializer 'sidekiq_indexing.init' do
ActiveSupport.on_load(:active_record) do
include(SidekiqIndexing::SearchableOverride)
end
end
end
end
class SunspotIndexer
include Sidekiq::Worker
def perform(klass_name, id)
Sunspot.index(klass_name.constantize.find(id))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment