1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

corrected ProjectIndexerWorker

This commit is contained in:
Sylvain 2020-05-05 12:37:13 +02:00
parent b204b1fbaf
commit 0609f444b0

View File

@ -1,20 +1,23 @@
# frozen_string_literal: true
# Index the projects to ElasticSearch
class ProjectIndexerWorker
include Sidekiq::Worker
sidekiq_options queue: 'elasticsearch', retry: true
Logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
Client = Elasticsearch::Model.client
def perform(operation, record_id)
logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
client = Elasticsearch::Model.client
logger.debug [operation, "ID: #{record_id}"]
case operation.to_s
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}'"
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}'"
end
end
end