Commit 6b2fde7e authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-geo-cursor-delete-events' into 'master'

Handle project deletions in Geo::LogCursor

See merge request !2452
parents 38ad142f 25a46f98
......@@ -64,6 +64,8 @@ module Gitlab
# Update repository
if event.repository_updated_event
handle_repository_update(event.repository_updated_event)
elsif event.repository_deleted_event
handle_repository_delete(event.repository_deleted_event)
end
end
end
......@@ -108,6 +110,25 @@ module Gitlab
registry.save!
end
def handle_repository_delete(deleted_event)
# Once we remove system hooks we can refactor
# GeoRepositoryDestroyWorker to avoid doing this
full_path = File.join(deleted_event.repository_storage_path,
deleted_event.deleted_path)
job_id = ::GeoRepositoryDestroyWorker.perform_async(
deleted_event.project_id,
deleted_event.deleted_project_name,
full_path)
Gitlab::Geo::Logger.info(
class: self.class.name,
message: "Deleted project",
project_id: deleted_event.project_id,
full_path: full_path,
job_id: job_id)
# No need to create a project entry if it doesn't exist
::Geo::ProjectRegistry.where(project_id: deleted_event.project_id).delete_all
end
def exit?
@exit
end
......
FactoryGirl.define do
factory :geo_event_log, class: Geo::EventLog do
trait :updated_event do
repository_updated_event factory: :geo_repository_update_event
end
trait :deleted_event do
repository_deleted_event factory: :geo_repository_delete_event
end
end
factory :geo_repository_update_event, class: Geo::RepositoryUpdatedEvent do
source 0
branches_affected 0
tags_affected 0
project
end
factory :geo_repository_delete_event, class: Geo::RepositoryDeletedEvent do
project
repository_storage_name { project.repository_storage }
repository_storage_path { project.repository_storage_path }
deleted_path { project.path_with_namespace }
deleted_project_name { project.name }
end
end
......@@ -22,7 +22,7 @@ describe Gitlab::Geo::LogCursor::Daemon do
end
context 'when processing a repository updated event' do
let(:event_log) { create(:geo_event_log) }
let(:event_log) { create(:geo_event_log, :updated_event) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
let(:repository_updated_event) { event_log.repository_updated_event }
......@@ -52,5 +52,32 @@ describe Gitlab::Geo::LogCursor::Daemon do
expect(registry.reload.resync_wiki).to be true
end
end
context 'when processing a repository deleted event' do
let(:event_log) { create(:geo_event_log, :deleted_event) }
let(:project) { event_log.repository_deleted_event.project }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
let(:repository_deleted_event) { event_log.repository_deleted_event }
before do
allow(subject).to receive(:exit?).and_return(false, true)
end
it 'does not create a new project registry' do
expect { subject.run! }.not_to change(Geo::ProjectRegistry, :count)
end
it 'schedules a GeoRepositoryDestroyWorker' do
project_id = repository_deleted_event.project_id
project_name = repository_deleted_event.deleted_project_name
full_path = File.join(repository_deleted_event.repository_storage_path,
repository_deleted_event.deleted_path)
expect(::GeoRepositoryDestroyWorker).to receive(:perform_async)
.with(project_id, project_name, full_path)
subject.run!
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