1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/workers/availability_indexer_worker.rb

22 lines
776 B
Ruby
Raw Normal View History

class AvailabilityIndexerWorker
include Sidekiq::Worker
sidekiq_options queue: 'elasticsearch', retry: true
2016-09-05 15:30:46 +02:00
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 = Availability.find(record_id)
Client.index index: Availability.index_name, type: Availability.document_type, id: record.id, body: record.as_indexed_json
#puts record.as_indexed_json
when /delete/
2016-09-05 15:30:46 +02:00
Client.delete index: Availability.index_name, type: Availability.document_type, id: record_id
else raise ArgumentError, "Unknown operation '#{operation}'"
end
end
end