Commit 5f1c3ce8 authored by Patrick Bajao's avatar Patrick Bajao

Handle git errors when cleaning up MR refs

Gitlab::Git::Repository::GitError and Gitlab::Git::CommandError
errors can get raised when trying to cleanup MR refs. This will
result to the worker being retried and move to dead queue when
failed after the retry limit.

We don't need to retry in this case as the job will be scheduled
again when picked up by `ScheduleMergeRequestCleanupRefsWorker`
that runs every minute via sidekiq cron.
parent ef36f93d
...@@ -36,6 +36,8 @@ module MergeRequests ...@@ -36,6 +36,8 @@ module MergeRequests
return error('Failed to update schedule.') unless update_schedule return error('Failed to update schedule.') unless update_schedule
success success
rescue Gitlab::Git::Repository::GitError, Gitlab::Git::CommandError => e
error(e.message)
end end
private private
......
---
title: Handle git errors when cleaning up MR refs
merge_request: 50250
author:
type: fixed
...@@ -91,6 +91,26 @@ RSpec.describe MergeRequests::CleanupRefsService do ...@@ -91,6 +91,26 @@ RSpec.describe MergeRequests::CleanupRefsService do
it_behaves_like 'service that does not clean up merge request refs' it_behaves_like 'service that does not clean up merge request refs'
end end
context 'when a git error is raised' do
context 'Gitlab::Git::Repository::GitError' do
before do
allow(merge_request.project.repository).to receive(:delete_refs).and_raise(Gitlab::Git::Repository::GitError)
end
it_behaves_like 'service that does not clean up merge request refs'
end
context 'Gitlab::Git::CommandError' do
before do
allow_next_instance_of(Gitlab::Git::KeepAround) do |keep_around|
expect(keep_around).to receive(:kept_around?).and_raise(Gitlab::Git::CommandError)
end
end
it_behaves_like 'service that does not clean up merge request refs'
end
end
context 'when cleanup schedule fails to update' do context 'when cleanup schedule fails to update' do
before do before do
allow(merge_request.cleanup_schedule).to receive(:update).and_return(false) allow(merge_request.cleanup_schedule).to receive(:update).and_return(false)
......
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