Commit 4c8fe525 authored by Michael Kozono's avatar Michael Kozono

Refactor RepositoryUpdatedService initializer

So consumers don’t need to know about `source`.
parent 74d906ea
...@@ -520,7 +520,8 @@ module EE ...@@ -520,7 +520,8 @@ module EE
override :after_import override :after_import
def after_import def after_import
super super
log_geo_events repository.log_geo_updated_event
wiki.repository.log_geo_updated_event
end end
override :import? override :import?
...@@ -573,13 +574,6 @@ module EE ...@@ -573,13 +574,6 @@ module EE
# Board limits are disabled in EE, so this method is just a no-op. # Board limits are disabled in EE, so this method is just a no-op.
end end
def log_geo_events
return unless ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::REPOSITORY).execute
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
end
override :after_rename_repository override :after_rename_repository
def after_rename_repository(full_path_before, path_before) def after_rename_repository(full_path_before, path_before)
super(full_path_before, path_before) super(full_path_before, path_before)
......
...@@ -81,8 +81,11 @@ module EE ...@@ -81,8 +81,11 @@ module EE
def log_geo_updated_event def log_geo_updated_event
return unless ::Gitlab::Geo.primary? return unless ::Gitlab::Geo.primary?
source = is_wiki ? ::Geo::RepositoryUpdatedEvent::WIKI : ::Geo::RepositoryUpdatedEvent::REPOSITORY ::Geo::RepositoryUpdatedService.new(self).execute
::Geo::RepositoryUpdatedService.new(self.project, source: source).execute end
def geo_updated_event_source
is_wiki ? Geo::RepositoryUpdatedEvent::WIKI : Geo::RepositoryUpdatedEvent::REPOSITORY
end end
end end
end end
...@@ -63,7 +63,7 @@ module EE ...@@ -63,7 +63,7 @@ module EE
end end
def sync_wiki_on_enable def sync_wiki_on_enable
::Geo::RepositoryUpdatedService.new(project, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute ::Geo::RepositoryUpdatedService.new(project.wiki.repository).execute
end end
end end
end end
......
...@@ -16,7 +16,7 @@ module EE ...@@ -16,7 +16,7 @@ module EE
def process_wiki_repository_update def process_wiki_repository_update
if ::Gitlab::Geo.primary? if ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(project, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute ::Geo::RepositoryUpdatedService.new(project.wiki.repository).execute
end end
end end
end end
......
...@@ -4,12 +4,12 @@ module Geo ...@@ -4,12 +4,12 @@ module Geo
RepositoryUpdateError = Class.new(StandardError) RepositoryUpdateError = Class.new(StandardError)
def initialize(project, params = {}) def initialize(repository, params = {})
@project = project @project = repository.project
@params = params @params = params
@refs = params.fetch(:refs, []) @refs = params.fetch(:refs, [])
@changes = params.fetch(:changes, []) @changes = params.fetch(:changes, [])
@source = params.fetch(:source, Geo::RepositoryUpdatedEvent::REPOSITORY) @source = repository.geo_updated_event_source
end end
def execute def execute
......
...@@ -12,7 +12,7 @@ module EE ...@@ -12,7 +12,7 @@ module EE
super super
if ::Gitlab::Geo.primary? if ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(post_received.project, refs: refs, changes: changes).execute ::Geo::RepositoryUpdatedService.new(post_received.project.repository, refs: refs, changes: changes).execute
end end
end end
...@@ -22,7 +22,7 @@ module EE ...@@ -22,7 +22,7 @@ module EE
update_wiki_es_indexes(post_received) update_wiki_es_indexes(post_received)
if ::Gitlab::Geo.primary? if ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(post_received.project, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute ::Geo::RepositoryUpdatedService.new(post_received.project.wiki.repository).execute
end end
end end
......
...@@ -1649,12 +1649,12 @@ describe Project do ...@@ -1649,12 +1649,12 @@ describe Project do
before do before do
allow(::Geo::RepositoryUpdatedService) allow(::Geo::RepositoryUpdatedService)
.to receive(:new) .to receive(:new)
.with(project, source: Geo::RepositoryUpdatedEvent::REPOSITORY) .with(project.repository)
.and_return(repository_updated_service) .and_return(repository_updated_service)
allow(::Geo::RepositoryUpdatedService) allow(::Geo::RepositoryUpdatedService)
.to receive(:new) .to receive(:new)
.with(project, source: Geo::RepositoryUpdatedEvent::WIKI) .with(project.wiki.repository)
.and_return(wiki_updated_service) .and_return(wiki_updated_service)
end end
......
...@@ -13,7 +13,7 @@ describe Geo::RepositoryUpdatedService do ...@@ -13,7 +13,7 @@ describe Geo::RepositoryUpdatedService do
end end
describe '#execute' do describe '#execute' do
subject { described_class.new(project, source: source) } subject { described_class.new(repository) }
shared_examples 'repository being updated' do shared_examples 'repository being updated' do
context 'when not running on a primary node' do context 'when not running on a primary node' do
...@@ -59,7 +59,7 @@ describe Geo::RepositoryUpdatedService do ...@@ -59,7 +59,7 @@ describe Geo::RepositoryUpdatedService do
end end
it 'does not raise an error when project have never been verified' do it 'does not raise an error when project have never been verified' do
expect { described_class.new(create(:project)) }.not_to raise_error expect { described_class.new(create(:project).repository) }.not_to raise_error
end end
it 'raises a Geo::RepositoryUpdatedService::RepositoryUpdateError when an error occurs' do it 'raises a Geo::RepositoryUpdatedService::RepositoryUpdateError when an error occurs' do
...@@ -74,14 +74,14 @@ describe Geo::RepositoryUpdatedService do ...@@ -74,14 +74,14 @@ describe Geo::RepositoryUpdatedService do
context 'when repository is being updated' do context 'when repository is being updated' do
include_examples 'repository being updated' do include_examples 'repository being updated' do
let(:source) { Geo::RepositoryUpdatedEvent::REPOSITORY } let(:repository) { project.repository }
let(:method_prefix) { 'repository' } let(:method_prefix) { 'repository' }
end end
end end
context 'when wiki is being updated' do context 'when wiki is being updated' do
include_examples 'repository being updated' do include_examples 'repository being updated' do
let(:source) { Geo::RepositoryUpdatedEvent::WIKI } let(:repository) { project.wiki.repository }
let(:method_prefix) { 'wiki' } let(:method_prefix) { 'wiki' }
end end
end end
......
...@@ -23,7 +23,7 @@ describe WikiPages::CreateService do ...@@ -23,7 +23,7 @@ describe WikiPages::CreateService do
allow(Gitlab::Geo).to receive(:primary?) { true } allow(Gitlab::Geo).to receive(:primary?) { true }
repository_updated_service = instance_double('::Geo::RepositoryUpdatedService') repository_updated_service = instance_double('::Geo::RepositoryUpdatedService')
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) { repository_updated_service } expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project.wiki.repository) { repository_updated_service }
expect(repository_updated_service).to receive(:execute) expect(repository_updated_service).to receive(:execute)
service.execute service.execute
...@@ -32,7 +32,7 @@ describe WikiPages::CreateService do ...@@ -32,7 +32,7 @@ describe WikiPages::CreateService do
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false } allow(Gitlab::Geo).to receive(:primary?) { false }
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project.wiki.repository)
service.execute service.execute
end end
......
...@@ -16,7 +16,7 @@ describe WikiPages::DestroyService do ...@@ -16,7 +16,7 @@ describe WikiPages::DestroyService do
allow(Gitlab::Geo).to receive(:primary?) { true } allow(Gitlab::Geo).to receive(:primary?) { true }
repository_updated_service = instance_double('::Geo::RepositoryUpdatedService') repository_updated_service = instance_double('::Geo::RepositoryUpdatedService')
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) { repository_updated_service } expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project.wiki.repository) { repository_updated_service }
expect(repository_updated_service).to receive(:execute) expect(repository_updated_service).to receive(:execute)
service.execute(page) service.execute(page)
...@@ -25,7 +25,7 @@ describe WikiPages::DestroyService do ...@@ -25,7 +25,7 @@ describe WikiPages::DestroyService do
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false } allow(Gitlab::Geo).to receive(:primary?) { false }
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project.wiki.repository)
service.execute(page) service.execute(page)
end end
......
...@@ -24,7 +24,7 @@ describe WikiPages::UpdateService do ...@@ -24,7 +24,7 @@ describe WikiPages::UpdateService do
allow(Gitlab::Geo).to receive(:primary?) { true } allow(Gitlab::Geo).to receive(:primary?) { true }
repository_updated_service = instance_double('::Geo::RepositoryUpdatedService') repository_updated_service = instance_double('::Geo::RepositoryUpdatedService')
expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) { repository_updated_service } expect(::Geo::RepositoryUpdatedService).to receive(:new).with(project.wiki.repository) { repository_updated_service }
expect(repository_updated_service).to receive(:execute) expect(repository_updated_service).to receive(:execute)
service.execute(page) service.execute(page)
...@@ -33,7 +33,7 @@ describe WikiPages::UpdateService do ...@@ -33,7 +33,7 @@ describe WikiPages::UpdateService do
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false } allow(Gitlab::Geo).to receive(:primary?) { false }
expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project, source: Geo::RepositoryUpdatedEvent::WIKI) expect(::Geo::RepositoryUpdatedService).not_to receive(:new).with(project.wiki.repository)
service.execute(page) service.execute(page)
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