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

24 lines
771 B
Ruby
Raw Normal View History

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