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
|
2019-06-06 16:34:53 +02:00
|
|
|
when /index/
|
|
|
|
begin
|
|
|
|
record = Availability.find(record_id)
|
|
|
|
Client.index index: Availability.index_name, type: Availability.document_type, id: record.id, body: record.as_indexed_json
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
STDERR.puts "Availability id(#{record_id}) will not be indexed in ElasticSearch as it does not exists anymore in database"
|
|
|
|
end
|
|
|
|
when /delete/
|
|
|
|
begin
|
|
|
|
Client.delete index: Availability.index_name, type: Availability.document_type, id: record_id
|
|
|
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
|
|
|
STDERR.puts "Availability id(#{record_id}) will not be deleted form ElasticSearch as it has not been already indexed"
|
|
|
|
end
|
|
|
|
else raise ArgumentError, "Unknown operation '#{operation}'"
|
2016-09-05 15:15:31 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|