Commit d9270f7a authored by Dmitry Gruzd's avatar Dmitry Gruzd Committed by Dylan Griffith

Fix ElasticCommitIndexerWorker FK violation

parent fa79e06f
---
title: Fix unnecessary Sidekiq errors/retries when project is deleted during indexing
merge_request: 45249
author:
type: fixed
......@@ -177,6 +177,15 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def update_index_status(to_sha)
unless Project.exists?(id: project.id)
Gitlab::Elasticsearch::Logger.build.debug(
message: 'Index status could not be updated as the project does not exist',
project_id: project.id,
wiki: index_wiki?
)
return false
end
raise "Invalid sha #{to_sha}" unless to_sha.present?
# An index_status should always be created,
......
......@@ -388,6 +388,25 @@ RSpec.describe Gitlab::Elastic::Indexer do
end
end
context 'when project no longer exists in database' do
let!(:logger_double) { instance_double(Gitlab::Elasticsearch::Logger) }
before do
allow(Gitlab::Elasticsearch::Logger).to receive(:build).and_return(logger_double)
allow(indexer).to receive(:run_indexer!) { Project.where(id: project.id).delete_all }
end
it 'does not raises an exception and prints log message' do
expect(logger_double).to receive(:debug).with(
message: 'Index status could not be updated as the project does not exist',
project_id: project.id,
wiki: false
)
expect(IndexStatus).not_to receive(:safe_find_or_create_by!).with(project_id: project.id)
expect { indexer.run }.not_to raise_error
end
end
def expect_popen
expect(Gitlab::Popen).to receive(:popen)
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