Commit b9765bd3 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '198503-retry-after-import-service' into 'master'

Add retry mechanism to after import

Closes #198503

See merge request gitlab-org/gitlab!23846
parents 7f7bafe3 2e64976d
......@@ -12,7 +12,9 @@ module Projects
service = Projects::HousekeepingService.new(@project)
service.execute do
repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
import_failure_service.with_retry(action: 'delete_all_refs') do
repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
end
end
# Right now we don't actually have a way to know if a project
......@@ -26,6 +28,10 @@ module Projects
private
def import_failure_service
@import_failure_service ||= Gitlab::ImportExport::ImportFailureService.new(@project)
end
def repository
@repository ||= @project.repository
end
......
......@@ -20,7 +20,7 @@ describe Projects::AfterImportService do
allow(housekeeping_service)
.to receive(:execute).and_yield
expect(housekeeping_service).to receive(:increment!)
allow(housekeeping_service).to receive(:increment!)
end
it 'performs housekeeping' do
......@@ -58,6 +58,52 @@ describe Projects::AfterImportService do
end
end
context 'when after import action throw non-retriable exception' do
let(:exception) { StandardError.new('after import error') }
before do
allow(repository)
.to receive(:delete_all_refs_except)
.and_raise(exception)
end
it 'throws after import error' do
expect { subject.execute }.to raise_exception('after import error')
end
end
context 'when after import action throw retriable exception one time' do
let(:exception) { GRPC::DeadlineExceeded.new }
before do
call_count = 0
allow(repository).to receive(:delete_all_refs_except).and_wrap_original do |original_method, *args|
call_count += 1
call_count > 1 ? original_method.call(*args) : raise(exception)
end
subject.execute
end
it 'removes refs/pull/**/*' do
expect(rugged.references.map(&:name))
.not_to include(%r{\Arefs/pull/})
end
it 'records the failures in the database', :aggregate_failures do
import_failure = ImportFailure.last
expect(import_failure.source).to eq('delete_all_refs')
expect(import_failure.project_id).to eq(project.id)
expect(import_failure.relation_key).to be_nil
expect(import_failure.relation_index).to be_nil
expect(import_failure.exception_class).to eq('GRPC::DeadlineExceeded')
expect(import_failure.exception_message).to be_present
expect(import_failure.correlation_id_value).not_to be_empty
end
end
def rugged
rugged_repo(repository)
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