Skip to content

Instantly share code, notes, and snippets.

@aledalgrande
Created August 10, 2014 01:50
Show Gist options
  • Save aledalgrande/e958581338e1e44be46c to your computer and use it in GitHub Desktop.
Save aledalgrande/e958581338e1e44be46c to your computer and use it in GitHub Desktop.
Sidekiq Elasticsearch
# app/models/article.rb
class Article < ActiveRecord::Base
include Elasticsearch::Model
# include Elasticsearch::Model::Callbacks
after_update :update_elasticsearch_index
def update_elasticsearch_index
ElasticSearchWorker.perform_async(Article, id)
end
end
# workers/elasticsearch_worker.rb
class ElasticsearchWorker
include Sidekiq::Worker
def perform(klass, id)
object = klass.find(id)
object.update_document
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment