Commit f923594b authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '221321-clear-hard-failure-on-force-update' into 'master'

Clear hard failure when updating mirror via UI

Closes #221321

See merge request gitlab-org/gitlab!34614
parents 4e6de9a4 31db8940
...@@ -6,15 +6,12 @@ class StartPullMirroringService < BaseService ...@@ -6,15 +6,12 @@ class StartPullMirroringService < BaseService
def execute def execute
import_state = project.import_state import_state = project.import_state
if import_state.hard_failed? return error('Mirroring for the project is on pause', 403) if params[:pause_on_hard_failure] && import_state.hard_failed?
return error('Mirroring for the project is on pause', 403) if params[:pause_on_hard_failure]
import_state.reset_retry_count
end
if update_now?(import_state) if update_now?(import_state)
import_state.force_import_job! import_state.force_import_job!
else else
import_state.reset_retry_count if import_state.hard_failed?
import_state.update(next_execution_timestamp: INTERVAL.since(import_state.last_update_at)) import_state.update(next_execution_timestamp: INTERVAL.since(import_state.last_update_at))
end end
......
---
title: Clear hard failure when updating mirror via UI
merge_request: 34614
author:
type: fixed
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe StartPullMirroringService do RSpec.describe StartPullMirroringService do
let(:project) { create(:project) } let(:project) { create(:project, :mirror, :repository) }
let(:import_state) { create(:import_state, project: project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:import_state) { project.import_state }
subject { described_class.new(project, user, pause_on_hard_failure: pause_on_hard_failure) } subject { described_class.new(project, user, pause_on_hard_failure: pause_on_hard_failure) }
...@@ -59,6 +59,17 @@ RSpec.describe StartPullMirroringService do ...@@ -59,6 +59,17 @@ RSpec.describe StartPullMirroringService do
end end
end end
shared_examples_for 'pull mirroring has not started' do |status|
it 'does not start pull mirroring' do
expect { execute }.to not_change { UpdateAllMirrorsWorker.jobs.size }
expect(execute[:status]).to eq(status)
end
end
before do
import_state.update(next_execution_timestamp: 1.minute.from_now)
end
context 'when pause_on_hard_failure is false' do context 'when pause_on_hard_failure is false' do
let(:pause_on_hard_failure) { false } let(:pause_on_hard_failure) { false }
...@@ -72,6 +83,14 @@ RSpec.describe StartPullMirroringService do ...@@ -72,6 +83,14 @@ RSpec.describe StartPullMirroringService do
it 'resets the import state retry_count' do it 'resets the import state retry_count' do
expect { execute }.to change { import_state.retry_count }.to(0) expect { execute }.to change { import_state.retry_count }.to(0)
end end
context 'when mirror is due to be updated' do
before do
import_state.update(next_execution_timestamp: 1.minute.ago)
end
it_behaves_like 'pull mirroring has started'
end
end end
context 'when does not reach the max retry limit yet' do context 'when does not reach the max retry limit yet' do
...@@ -81,6 +100,14 @@ RSpec.describe StartPullMirroringService do ...@@ -81,6 +100,14 @@ RSpec.describe StartPullMirroringService do
it_behaves_like 'pull mirroring has started' it_behaves_like 'pull mirroring has started'
it_behaves_like 'retry count did not reset' it_behaves_like 'retry count did not reset'
context 'when mirror is due to be updated' do
before do
import_state.update(next_execution_timestamp: 1.minute.ago)
end
it_behaves_like 'pull mirroring has not started', :success
end
end end
end end
...@@ -93,11 +120,7 @@ RSpec.describe StartPullMirroringService do ...@@ -93,11 +120,7 @@ RSpec.describe StartPullMirroringService do
end end
it_behaves_like 'retry count did not reset' it_behaves_like 'retry count did not reset'
it_behaves_like 'pull mirroring has not started', :error
it 'does not start pull mirroring' do
expect { execute }.to not_change { UpdateAllMirrorsWorker.jobs.size }
expect(execute[:status]).to eq(:error)
end
end end
context 'when does not reach the max retry limit yet' do context 'when does not reach the max retry limit yet' do
...@@ -107,6 +130,14 @@ RSpec.describe StartPullMirroringService do ...@@ -107,6 +130,14 @@ RSpec.describe StartPullMirroringService do
it_behaves_like 'pull mirroring has started' it_behaves_like 'pull mirroring has started'
it_behaves_like 'retry count did not reset' it_behaves_like 'retry count did not reset'
context 'when mirror is due to be updated' do
before do
import_state.update(next_execution_timestamp: 1.minute.ago)
end
it_behaves_like 'pull mirroring has not started', :success
end
end 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