mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-30 11:24:21 +01:00
22 lines
718 B
Ruby
22 lines
718 B
Ruby
class IndexerWorker
|
|
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.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
|
|
#puts record.as_indexed_json
|
|
when /delete/
|
|
Client.delete index: 'fablab', type: 'projects', id: record_id
|
|
else raise ArgumentError, "Unknown operation '#{operation}'"
|
|
end
|
|
end
|
|
end
|