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