From b5246ae1cfc8a66d644dd54a65e17b4bde005174 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 4 Jan 2017 15:20:54 +0100 Subject: [PATCH] [bug] AvailabilityIndexerWorker crash availabilities deleted just after their creation --- CHANGELOG.md | 1 + app/workers/availability_indexer_worker.rb | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d095160c5..3950ee773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fix a bug: unable to compute user's age when they were born on february 29th and current year is not a leap year - Fix a bug: wrong statistics about hours available for machines reservation. Fix requires user action (1) - Fix a bug: when regenerating statistics, previous values are not fully removed (only 10 firsts), resulting in wrong statistics generation +- Fix a bug: when deleting an availability just after its creation, the indexer workers crash and retries for a month - [TODO DEPLOY] remove possible value `application/` in `ALLOWED_MIME_TYPES` list, in environment variable - [TODO DEPLOY] `rails runner StatisticCustomAggregation.destroy_all`, then `rake db:seed`, then `rake fablab:es_build_availabilities_index` (1) diff --git a/app/workers/availability_indexer_worker.rb b/app/workers/availability_indexer_worker.rb index a902ed718..c26acadad 100644 --- a/app/workers/availability_indexer_worker.rb +++ b/app/workers/availability_indexer_worker.rb @@ -10,11 +10,18 @@ class AvailabilityIndexerWorker case operation.to_s when /index/ - record = Availability.find(record_id) - Client.index index: Availability.index_name, type: Availability.document_type, id: record.id, body: record.as_indexed_json - #puts record.as_indexed_json + 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/ - Client.delete index: Availability.index_name, type: Availability.document_type, id: record_id + 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}'" end end