Rename Geo::PushService to Geo::PushEventStore

parent e48bba6f
module Geo module Geo
class PushService class PushEventStore
attr_reader :project, :source, :refs, :changes attr_reader :project, :source, :refs, :changes
def initialize(project, refs: [], changes: [], source: Geo::PushEvent::REPOSITORY) def initialize(project, refs: [], changes: [], source: Geo::PushEvent::REPOSITORY)
...@@ -9,7 +9,7 @@ module Geo ...@@ -9,7 +9,7 @@ module Geo
@source = source @source = source
end end
def execute def create
return unless Gitlab::Geo.primary? return unless Gitlab::Geo.primary?
Geo::EventLog.transaction do Geo::EventLog.transaction do
......
...@@ -18,7 +18,7 @@ class PostReceive ...@@ -18,7 +18,7 @@ class PostReceive
post_received = Gitlab::GitPostReceive.new(project, identifier, changes) post_received = Gitlab::GitPostReceive.new(project, identifier, changes)
if is_wiki if is_wiki
process_wiki_update(post_received) process_wiki_repository_update(post_received)
else else
process_project_changes(post_received) process_project_changes(post_received)
process_repository_update(post_received) process_repository_update(post_received)
...@@ -42,18 +42,18 @@ class PostReceive ...@@ -42,18 +42,18 @@ class PostReceive
end end
# Generate repository update event on Geo event log when Geo is enabled # Generate repository update event on Geo event log when Geo is enabled
Geo::PushService.new(post_received.project, refs: refs.to_a, changes: changes).execute Geo::PushEventStore.new(post_received.project, refs: refs.to_a, changes: changes).create
hook_data = Gitlab::DataBuilder::Repository.update(post_received.project, @user, changes, refs.to_a) hook_data = Gitlab::DataBuilder::Repository.update(post_received.project, @user, changes, refs.to_a)
SystemHooksService.new.execute_hooks(hook_data, :repository_update_hooks) SystemHooksService.new.execute_hooks(hook_data, :repository_update_hooks)
end end
def process_wiki_update(post_received) def process_wiki_repository_update(post_received)
update_wiki_es_indexes(post_received) update_wiki_es_indexes(post_received)
if Gitlab::Geo.enabled? if Gitlab::Geo.enabled?
# Generate wiki update event on Geo event log # Generate wiki update event on Geo event log
Geo::PushService.new(post_received.project, source: Geo::PushEvent::WIKI).execute Geo::PushEventStore.new(post_received.project, source: Geo::PushEvent::WIKI).create
# Triggers repository update on secondary nodes # Triggers repository update on secondary nodes
Gitlab::Geo.notify_wiki_update(post_received.project) Gitlab::Geo.notify_wiki_update(post_received.project)
......
require 'spec_helper' require 'spec_helper'
describe Geo::PushService, services: true do describe Geo::PushEventStore, services: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:blankrev) { Gitlab::Git::BLANK_SHA } let(:blankrev) { Gitlab::Git::BLANK_SHA }
let(:refs) { ['refs/heads/tést', 'refs/tags/tag'] } let(:refs) { ['refs/heads/tést', 'refs/tags/tag'] }
...@@ -12,13 +12,13 @@ describe Geo::PushService, services: true do ...@@ -12,13 +12,13 @@ describe Geo::PushService, services: true do
] ]
end end
describe '#execute' do describe '#create' do
it 'does not create a push event when not running on a primary node' do it 'does not create a push event when not running on a primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false } allow(Gitlab::Geo).to receive(:primary?) { false }
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.execute }.not_to change(Geo::PushEvent, :count) expect { subject.create }.not_to change(Geo::PushEvent, :count)
end end
context 'when running on a primary node' do context 'when running on a primary node' do
...@@ -29,14 +29,14 @@ describe Geo::PushService, services: true do ...@@ -29,14 +29,14 @@ describe Geo::PushService, services: true do
it 'creates a push event' do it 'creates a push event' do
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.execute }.to change(Geo::PushEvent, :count).by(1) expect { subject.create }.to change(Geo::PushEvent, :count).by(1)
end end
context 'when repository is beign udpated' do context 'when repository is beign udpated' do
it 'does not track ref name when post-receive event affect multiple refs' do it 'does not track ref name when post-receive event affect multiple refs' do
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
subject.execute subject.create
expect(Geo::PushEvent.last.ref).to be_nil expect(Geo::PushEvent.last.ref).to be_nil
end end
...@@ -46,7 +46,7 @@ describe Geo::PushService, services: true do ...@@ -46,7 +46,7 @@ describe Geo::PushService, services: true do
changes = [{ before: '123456', after: blankrev, ref: 'refs/heads/tést' }] changes = [{ before: '123456', after: blankrev, ref: 'refs/heads/tést' }]
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
subject.execute subject.create
expect(Geo::PushEvent.last.ref).to eq 'refs/heads/tést' expect(Geo::PushEvent.last.ref).to eq 'refs/heads/tést'
end end
...@@ -54,7 +54,7 @@ describe Geo::PushService, services: true do ...@@ -54,7 +54,7 @@ describe Geo::PushService, services: true do
it 'tracks number of branches post-receive event affects' do it 'tracks number of branches post-receive event affects' do
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
subject.execute subject.create
expect(Geo::PushEvent.last.branches_affected).to eq 1 expect(Geo::PushEvent.last.branches_affected).to eq 1
end end
...@@ -62,7 +62,7 @@ describe Geo::PushService, services: true do ...@@ -62,7 +62,7 @@ describe Geo::PushService, services: true do
it 'tracks number of tags post-receive event affects' do it 'tracks number of tags post-receive event affects' do
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
subject.execute subject.create
expect(Geo::PushEvent.last.tags_affected).to eq 1 expect(Geo::PushEvent.last.tags_affected).to eq 1
end end
...@@ -76,7 +76,7 @@ describe Geo::PushService, services: true do ...@@ -76,7 +76,7 @@ describe Geo::PushService, services: true do
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
subject.execute subject.create
expect(Geo::PushEvent.last.new_branch).to eq true expect(Geo::PushEvent.last.new_branch).to eq true
end end
...@@ -89,7 +89,7 @@ describe Geo::PushService, services: true do ...@@ -89,7 +89,7 @@ describe Geo::PushService, services: true do
] ]
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
subject.execute subject.create
expect(Geo::PushEvent.last.remove_branch).to eq true expect(Geo::PushEvent.last.remove_branch).to eq true
end end
...@@ -99,7 +99,7 @@ describe Geo::PushService, services: true do ...@@ -99,7 +99,7 @@ describe Geo::PushService, services: true do
it 'does not track any information' do it 'does not track any information' do
subject = described_class.new(project, source: Geo::PushEvent::WIKI) subject = described_class.new(project, source: Geo::PushEvent::WIKI)
subject.execute subject.create
push_event = Geo::PushEvent.last push_event = Geo::PushEvent.last
......
...@@ -110,8 +110,8 @@ describe PostReceive do ...@@ -110,8 +110,8 @@ describe PostReceive do
allow(subject).to receive(:process_project_changes).and_return(true) allow(subject).to receive(:process_project_changes).and_return(true)
end end
it 'calls Geo::PushService' do it 'calls Geo::PushEventStore' do
expect_any_instance_of(Geo::PushService).to receive(:execute) expect_any_instance_of(Geo::PushEventStore).to receive(:create)
subject.perform(pwd(project), key_id, base64_changes) subject.perform(pwd(project), key_id, base64_changes)
end end
...@@ -124,11 +124,11 @@ describe PostReceive do ...@@ -124,11 +124,11 @@ describe PostReceive do
end end
describe '#process_wiki_update' do describe '#process_wiki_update' do
it 'triggers Geo::PushService when Geo is enabled' do it 'triggers Geo::PushEventStore when Geo is enabled' do
allow(Gitlab::Geo).to receive(:enabled?) { true } allow(Gitlab::Geo).to receive(:enabled?) { true }
expect(Geo::PushService).to receive(:new).with(instance_of(Project), source: Geo::PushEvent::WIKI).and_call_original expect(Geo::PushEventStore).to receive(:new).with(instance_of(Project), source: Geo::PushEvent::WIKI).and_call_original
expect_any_instance_of(Geo::PushService).to receive(:execute) expect_any_instance_of(Geo::PushEventStore).to receive(:create)
described_class.new.perform("#{pwd(project)}.wiki", key_id, base64_changes) described_class.new.perform("#{pwd(project)}.wiki", key_id, base64_changes)
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