2016-09-05 15:15:31 +02:00
|
|
|
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
|
2016-09-05 15:15:31 +02:00
|
|
|
|
|
|
|
def perform(operation, record_id)
|
|
|
|
logger.debug [operation, "ID: #{record_id}"]
|
|
|
|
|
|
|
|
case operation.to_s
|
|
|
|
when /index/
|
|
|
|
record = Availability.find(record_id)
|
2016-09-06 16:32:41 +02:00
|
|
|
Client.index index: Availability.index_name, type: Availability.document_type, id: record.id, body: record.as_indexed_json
|
2016-09-05 15:15:31 +02:00
|
|
|
#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
|
2016-09-05 15:15:31 +02:00
|
|
|
else raise ArgumentError, "Unknown operation '#{operation}'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|