Commit f91c27a2 authored by Dylan Griffith's avatar Dylan Griffith

Add logging to error handling in ElasticIndexerWorker

parent e45c2720
...@@ -32,13 +32,16 @@ class ElasticIndexerWorker ...@@ -32,13 +32,16 @@ class ElasticIndexerWorker
client.delete index: klass.index_name, type: klass.document_type, id: es_id client.delete index: klass.index_name, type: klass.document_type, id: es_id
end end
end end
rescue Elasticsearch::Transport::Transport::Errors::NotFound, ActiveRecord::RecordNotFound rescue Elasticsearch::Transport::Transport::Errors::NotFound, ActiveRecord::RecordNotFound => e
# These errors can happen in several cases, including: # These errors can happen in several cases, including:
# - A record is updated, then removed before the update is handled # - A record is updated, then removed before the update is handled
# - Indexing is enabled, but not every item has been indexed yet - updating # - Indexing is enabled, but not every item has been indexed yet - updating
# and deleting the un-indexed records will raise exception # and deleting the un-indexed records will raise exception
# #
# We can ignore these. # We can ignore these.
logger.error(message: 'elastic_indexer_worker_caught_exception', error_class: e.class.name, error_message: e.message)
true true
end end
...@@ -65,4 +68,8 @@ class ElasticIndexerWorker ...@@ -65,4 +68,8 @@ class ElasticIndexerWorker
} }
}) })
end end
def logger
@logger ||= ::Gitlab::Elasticsearch::Logger.build
end
end end
...@@ -103,4 +103,18 @@ describe ElasticIndexerWorker, :elastic do ...@@ -103,4 +103,18 @@ describe ElasticIndexerWorker, :elastic do
subject.perform("index", 'Project', object.id, object.es_id) subject.perform("index", 'Project', object.id, object.es_id)
end.to raise_error end.to raise_error
end end
it 'ignores Elasticsearch::Transport::Transport::Errors::NotFound error' do
object = create(:project)
expect_next_instance_of(Elastic::IndexRecordService) do |service|
allow(service).to receive(:execute).and_raise(Elasticsearch::Transport::Transport::Errors::NotFound)
end
expect(subject.perform("index", 'Project', object.id, object.es_id)).to eq(true)
end
it 'ignores missing records' do
expect(subject.perform("index", 'Project', -1, 'project_-1')).to eq(true)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment