Rename Geo::PushService to Geo::PushEventStore

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