Commit 64c15df3 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'geo-repository-clean-up-worker' into 'master'

Geo - Improve Geo::RepositoriesCleanUpWorker

Closes #3132

See merge request !2650
parents ec33952f 0fe8ce94
......@@ -2,6 +2,7 @@ module Geo
class RepositoriesCleanUpWorker
include Sidekiq::Worker
include GeoQueue
include Gitlab::ShellAdapter
BATCH_SIZE = 250
LEASE_TIMEOUT = 60.minutes
......@@ -27,6 +28,9 @@ module Geo
private
def clean_up_repositories(project)
# There is a possibility project does not have repository or wiki
return true unless gitlab_shell.exists?(project.repository_storage_path, "#{project.disk_path}.git")
job_id = ::GeoRepositoryDestroyWorker.perform_async(project.id, project.name, project.full_path)
if job_id
......
require 'spec_helper'
describe Geo::RepositoriesCleanUpWorker do
let!(:geo_node) { create(:geo_node) }
let(:synced_group) { create(:group) }
let!(:project_in_synced_group) { create(:project, group: synced_group) }
let!(:unsynced_project) { create(:project) }
describe '#perform' do
let(:geo_node) { create(:geo_node) }
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { true }
end
context 'when node has namespace restrictions' do
let(:synced_group) { create(:group) }
let(:geo_node) { create(:geo_node, namespaces: [synced_group]) }
it 'performs GeoRepositoryDestroyWorker for each project that does not belong to selected namespaces to replicate' do
geo_node.update_attribute(:namespaces, [synced_group])
project_in_synced_group = create(:project, group: synced_group)
unsynced_project = create(:project, :repository)
expect(GeoRepositoryDestroyWorker).to receive(:perform_async)
.with(unsynced_project.id, unsynced_project.name, unsynced_project.full_path)
.once.and_return(1)
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
.with(project_in_synced_group.id, project_in_synced_group.name, project_in_synced_group.full_path)
subject.perform(geo_node.id)
end
end
context 'when does not node have namespace restrictions' do
it 'does not perform GeoRepositoryDestroyWorker' do
it 'does not perform GeoRepositoryDestroyWorker when repository does not exist' do
create(:project)
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
subject.perform(geo_node.id)
end
end
context 'when cannnot obtain a lease' do
it 'does not perform GeoRepositoryDestroyWorker' do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { false }
it 'does not perform GeoRepositoryDestroyWorker when does not node have namespace restrictions' do
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
subject.perform(geo_node.id)
end
subject.perform(geo_node.id)
end
it 'does not perform GeoRepositoryDestroyWorker when cannnot obtain a lease' do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { false }
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
subject.perform(geo_node.id)
end
context 'when Geo node could not be found' do
it 'does not raise an error' do
expect { subject.perform(-1) }.not_to raise_error
end
it 'does not raise an error when node could not be found' do
expect { subject.perform(-1) }.not_to raise_error
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