Schedules repository sync when handling events in the Geo Log Cursor

parent 66062c09
...@@ -5,6 +5,7 @@ module Gitlab ...@@ -5,6 +5,7 @@ module Gitlab
VERSION = '0.1.0'.freeze VERSION = '0.1.0'.freeze
POOL_WAIT = 5.seconds.freeze POOL_WAIT = 5.seconds.freeze
BATCH_SIZE = 250 BATCH_SIZE = 250
SYNC_BACKOFF_DELAY = 5.minutes
attr_reader :options attr_reader :options
...@@ -121,6 +122,7 @@ module Gitlab ...@@ -121,6 +122,7 @@ module Gitlab
registry.save! registry.save!
::Geo::ProjectSyncWorker.perform_in(SYNC_BACKOFF_DELAY, event.project_id, Time.now)
end end
def handle_repository_updated(event_log) def handle_repository_updated(event_log)
...@@ -136,6 +138,8 @@ module Gitlab ...@@ -136,6 +138,8 @@ module Gitlab
resync_wiki: registry.resync_wiki) resync_wiki: registry.resync_wiki)
registry.save! registry.save!
::Geo::ProjectSyncWorker.perform_in(SYNC_BACKOFF_DELAY, event.project_id, Time.now)
end end
def handle_repository_deleted(event_log) def handle_repository_deleted(event_log)
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Geo::LogCursor::Daemon, :postgresql do describe Gitlab::Geo::LogCursor::Daemon, :postgresql do
include ::EE::GeoHelpers include ::EE::GeoHelpers
...@@ -31,7 +30,8 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do ...@@ -31,7 +30,8 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do
end end
context 'when replaying a repository created event' do context 'when replaying a repository created event' do
let(:repository_created_event) { create(:geo_repository_created_event) } let(:project) { create(:project) }
let(:repository_created_event) { create(:geo_repository_created_event, project: project) }
let(:event_log) { create(:geo_event_log, repository_created_event: repository_created_event) } let(:event_log) { create(:geo_event_log, repository_created_event: repository_created_event) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) } let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
...@@ -48,7 +48,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do ...@@ -48,7 +48,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do
registry = Geo::ProjectRegistry.last registry = Geo::ProjectRegistry.last
expect(registry).to have_attributes(resync_repository: true, resync_wiki: true) expect(registry).to have_attributes(project_id: project.id, resync_repository: true, resync_wiki: true)
end end
it 'sets resync_wiki to false if wiki_path is nil' do it 'sets resync_wiki to false if wiki_path is nil' do
...@@ -58,14 +58,22 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do ...@@ -58,14 +58,22 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do
registry = Geo::ProjectRegistry.last registry = Geo::ProjectRegistry.last
expect(registry).to have_attributes(resync_repository: true, resync_wiki: false) expect(registry).to have_attributes(project_id: project.id, resync_repository: true, resync_wiki: false)
end
it 'performs Geo::ProjectSyncWorker' do
expect(Geo::ProjectSyncWorker).to receive(:perform_in)
.with(anything, project.id, anything).once.and_return(spy)
subject.run!
end end
end end
context 'when replaying a repository updated event' do context 'when replaying a repository updated event' do
let(:event_log) { create(:geo_event_log, :updated_event) } let(:project) { create(:project) }
let(:repository_updated_event) { create(:geo_repository_updated_event, project: project) }
let(:event_log) { create(:geo_event_log, repository_updated_event: repository_updated_event) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) } let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
let(:repository_updated_event) { event_log.repository_updated_event }
before do before do
allow(subject).to receive(:exit?).and_return(false, true) allow(subject).to receive(:exit?).and_return(false, true)
...@@ -92,6 +100,13 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do ...@@ -92,6 +100,13 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do
expect(registry.reload.resync_wiki).to be true expect(registry.reload.resync_wiki).to be true
end end
it 'performs Geo::ProjectSyncWorker' do
expect(Geo::ProjectSyncWorker).to receive(:perform_in)
.with(anything, project.id, anything).once.and_return(spy)
subject.run!
end
end end
context 'when replaying a repository deleted event' do context 'when replaying a repository deleted event' do
...@@ -156,6 +171,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do ...@@ -156,6 +171,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do
before do before do
allow(subject).to receive(:exit?).and_return(false, true) allow(subject).to receive(:exit?).and_return(false, true)
allow(Geo::ProjectSyncWorker).to receive(:perform_in).and_return(spy)
end end
it 'replays events for projects that belong to selected namespaces to replicate' do it 'replays events for projects that belong to selected namespaces to replicate' do
......
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