Commit a4a657cb authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '338782-make-repository-update-mirror-worker-idempotent' into 'master'

Make RepositoryUpdateMirrorWorker idempotent

See merge request gitlab-org/gitlab!69725
parents 9287b27a 47660596
...@@ -1127,7 +1127,7 @@ ...@@ -1127,7 +1127,7 @@
:urgency: :low :urgency: :low
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 1 :weight: 1
:idempotent: :idempotent: true
:tags: [] :tags: []
- :name: requirements_management_import_requirements_csv - :name: requirements_management_import_requirements_csv
:worker_name: RequirementsManagement::ImportRequirementsCsvWorker :worker_name: RequirementsManagement::ImportRequirementsCsvWorker
......
# frozen_string_literal: true # frozen_string_literal: true
class RepositoryUpdateMirrorWorker # rubocop:disable Scalability/IdempotentWorker class RepositoryUpdateMirrorWorker
UpdateError = Class.new(StandardError) UpdateError = Class.new(StandardError)
include ApplicationWorker include ApplicationWorker
idempotent!
data_consistency :always data_consistency :always
include Gitlab::ShellAdapter
include ProjectStartImport include ProjectStartImport
feature_category :source_code_management feature_category :source_code_management
......
...@@ -8,8 +8,10 @@ RSpec.describe RepositoryUpdateMirrorWorker do ...@@ -8,8 +8,10 @@ RSpec.describe RepositoryUpdateMirrorWorker do
let!(:project) { create(:project) } let!(:project) { create(:project) }
let!(:import_state) { create(:import_state, :mirror, :scheduled, project: project) } let!(:import_state) { create(:import_state, :mirror, :scheduled, project: project) }
subject(:worker) { described_class.new }
before do before do
allow(subject).to receive(:jid).and_return(jid) allow(worker).to receive(:jid).and_return(jid)
end end
it 'sets status as finished when update mirror service executes successfully' do it 'sets status as finished when update mirror service executes successfully' do
...@@ -58,5 +60,15 @@ RSpec.describe RepositoryUpdateMirrorWorker do ...@@ -58,5 +60,15 @@ RSpec.describe RepositoryUpdateMirrorWorker do
expect { subject.perform(started_project.id) }.to change { import_state.reload.status }.to('finished') expect { subject.perform(started_project.id) }.to change { import_state.reload.status }.to('finished')
end end
end end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [project.id] }
before do
allow_next_instance_of(Projects::UpdateMirrorService) do |instance|
allow(instance).to receive(:execute).and_return(status: :success)
end
end
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