Commit 5db05f8c authored by Markus Koller's avatar Markus Koller

Merge branch '299059-fj-create-repository-storage-move-worker' into 'master'

Create worker to handle group repository storage moves

See merge request gitlab-org/gitlab!52701
parents 5d588d80 29e753c1
......@@ -160,6 +160,8 @@
- 1
- - group_wikis_git_garbage_collect
- 1
- - groups_update_repository_storage
- 1
- - hashed_storage
- 1
- - import_issues_csv
......
......@@ -17,7 +17,11 @@ module Groups
override :schedule_repository_storage_update_worker
def schedule_repository_storage_update_worker
# No-op. It will be implemented in https://gitlab.com/gitlab-org/gitlab/-/issues/299059
Groups::UpdateRepositoryStorageWorker.perform_async(
group_id,
destination_storage_name,
id
)
end
private
......
......@@ -773,6 +773,14 @@
:weight: 1
:idempotent:
:tags: []
- :name: groups_update_repository_storage
:feature_category: :gitaly
:has_external_dependencies:
:urgency: :throttled
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: incident_management_apply_incident_sla_exceeded_label
:feature_category: :incident_management
:has_external_dependencies:
......
# frozen_string_literal: true
module Groups
class UpdateRepositoryStorageWorker # rubocop:disable Scalability/IdempotentWorker
extend ::Gitlab::Utils::Override
include ::UpdateRepositoryStorageWorker
private
override :find_repository_storage_move
def find_repository_storage_move(repository_storage_move_id)
::Groups::RepositoryStorageMove.find(repository_storage_move_id)
end
override :find_container
def find_container(container_id)
::Group.find(container_id)
end
override :update_repository_storage
def update_repository_storage(repository_storage_move)
::Groups::UpdateRepositoryStorageService.new(repository_storage_move).execute
end
end
end
......@@ -3,10 +3,11 @@
require 'spec_helper'
RSpec.describe Groups::RepositoryStorageMove, type: :model do
it_behaves_like 'handles repository moves', check_worker: false do
it_behaves_like 'handles repository moves' do
let_it_be_with_refind(:container) { create(:group) }
let(:repository_storage_factory_key) { :group_repository_storage_move }
let(:error_key) { :group }
let(:repository_storage_worker) { Groups::UpdateRepositoryStorageWorker }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::UpdateRepositoryStorageWorker do
subject { described_class.new }
it_behaves_like 'an update storage move worker' do
let_it_be_with_refind(:container) { create(:group, :wiki_repo) }
let_it_be(:repository_storage_move) { create(:group_repository_storage_move) }
let(:service_klass) { Groups::UpdateRepositoryStorageService }
let(:repository_storage_move_klass) { Groups::RepositoryStorageMove }
end
end
# frozen_string_literal: true
RSpec.shared_examples 'handles repository moves' do |check_worker: true|
RSpec.shared_examples 'handles repository moves' do
describe 'associations' do
it { is_expected.to belong_to(:container) }
end
......@@ -61,25 +61,23 @@ RSpec.shared_examples 'handles repository moves' do |check_worker: true|
context 'when in the default state' do
subject(:storage_move) { create(repository_storage_factory_key, container: container, destination_storage_name: 'test_second_storage') }
if check_worker
context 'and transits to scheduled' do
it 'triggers the corresponding repository storage worker' do
expect(repository_storage_worker).to receive(:perform_async).with(container.id, 'test_second_storage', storage_move.id)
context 'and transits to scheduled' do
it 'triggers the corresponding repository storage worker' do
expect(repository_storage_worker).to receive(:perform_async).with(container.id, 'test_second_storage', storage_move.id)
storage_move.schedule!
storage_move.schedule!
expect(container).to be_repository_read_only
end
expect(container).to be_repository_read_only
end
context 'when the transition fails' do
it 'does not trigger the corresponding repository storage worker and adds an error' do
allow(storage_move.container).to receive(:set_repository_read_only!).and_raise(StandardError, 'foobar')
expect(repository_storage_worker).not_to receive(:perform_async)
context 'when the transition fails' do
it 'does not trigger the corresponding repository storage worker and adds an error' do
allow(storage_move.container).to receive(:set_repository_read_only!).and_raise(StandardError, 'foobar')
expect(repository_storage_worker).not_to receive(:perform_async)
storage_move.schedule!
storage_move.schedule!
expect(storage_move.errors[error_key]).to include('foobar')
end
expect(storage_move.errors[error_key]).to include('foobar')
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