1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-02 13:24:20 +01:00
fab-manager/app/workers/project_indexer_worker.rb

21 lines
709 B
Ruby
Raw Normal View History

class ProjectIndexerWorker
2016-03-23 18:39:41 +01:00
include Sidekiq::Worker
sidekiq_options queue: 'elasticsearch', retry: true
Logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
Client = Elasticsearch::Model.client
def perform(operation, record_id)
logger.debug [operation, "ID: #{record_id}"]
case operation.to_s
when /index/
record = Project.find(record_id)
2016-09-05 15:30:46 +02:00
Client.index index: Project.index_name, type: Project.document_type, id: record.id, body: record.as_indexed_json
2016-03-23 18:39:41 +01:00
when /delete/
2016-09-05 15:30:46 +02:00
Client.delete index: Project.index_name, type: Project.document_type, id: record_id
2016-03-23 18:39:41 +01:00
else raise ArgumentError, "Unknown operation '#{operation}'"
end
end
end