Add Geo::ProjectSyncWorker

parent 3283c713
module Geo
class ProjectSyncWorker
include Sidekiq::Worker
sidekiq_options queue: :geo, retry: 3, dead: false
sidekiq_retry_in { |count| 30 * count }
sidekiq_retries_exhausted do |msg, _|
Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
end
def perform(project_id, scheduled_time)
Geo::RepositorySyncService.new(project_id).execute
rescue ActiveRecord::RecordNotFound
logger.error("Couldn't find project with ID=#{project_id}, skipping syncing")
end
end
end
...@@ -13,13 +13,13 @@ describe GeoRepositorySyncWorker do ...@@ -13,13 +13,13 @@ describe GeoRepositorySyncWorker do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { true } allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { true }
end end
it 'performs Geo::RepositorySyncService for each project' do it 'performs Geo::ProjectSyncWorker for each project' do
expect(Geo::RepositorySyncService).to receive(:new).twice.and_return(spy) expect(Geo::ProjectSyncWorker).to receive(:perform_in).twice.and_return(spy)
subject.perform subject.perform
end end
it 'performs Geo::RepositorySyncService for projects where last attempt to sync failed' do it 'performs Geo::ProjectSyncWorker for projects where last attempt to sync failed' do
Geo::ProjectRegistry.create( Geo::ProjectRegistry.create(
project: project_1, project: project_1,
last_repository_synced_at: DateTime.now, last_repository_synced_at: DateTime.now,
...@@ -34,12 +34,12 @@ describe GeoRepositorySyncWorker do ...@@ -34,12 +34,12 @@ describe GeoRepositorySyncWorker do
resync_wiki: false resync_wiki: false
) )
expect(Geo::RepositorySyncService).to receive(:new).once.and_return(spy) expect(Geo::ProjectSyncWorker).to receive(:perform_in).once.and_return(spy)
subject.perform subject.perform
end end
it 'performs Geo::RepositorySyncService for synced projects updated recently' do it 'performs Geo::ProjectSyncWorker for synced projects updated recently' do
Geo::ProjectRegistry.create( Geo::ProjectRegistry.create(
project: project_1, project: project_1,
last_repository_synced_at: 2.days.ago, last_repository_synced_at: 2.days.ago,
...@@ -64,39 +64,31 @@ describe GeoRepositorySyncWorker do ...@@ -64,39 +64,31 @@ describe GeoRepositorySyncWorker do
resync_wiki: true resync_wiki: true
) )
expect(Geo::RepositorySyncService).to receive(:new).twice.and_return(spy) expect(Geo::ProjectSyncWorker).to receive(:perform_in).twice.and_return(spy)
subject.perform subject.perform
end end
it 'does not perform Geo::RepositorySyncService when secondary role is disabled' do it 'does not perform Geo::ProjectSyncWorker when secondary role is disabled' do
allow(Gitlab::Geo).to receive(:secondary_role_enabled?) { false } allow(Gitlab::Geo).to receive(:secondary_role_enabled?) { false }
expect(Geo::RepositorySyncService).not_to receive(:new) expect(Geo::ProjectSyncWorker).not_to receive(:perform_in)
subject.perform subject.perform
end end
it 'does not perform Geo::RepositorySyncService when primary node does not exists' do it 'does not perform Geo::ProjectSyncWorker when primary node does not exists' do
allow(Gitlab::Geo).to receive(:primary_node) { nil } allow(Gitlab::Geo).to receive(:primary_node) { nil }
expect(Geo::RepositorySyncService).not_to receive(:new) expect(Geo::ProjectSyncWorker).not_to receive(:perform_in)
subject.perform subject.perform
end end
it 'does not perform Geo::RepositorySyncService when node is disabled' do it 'does not perform Geo::ProjectSyncWorker when node is disabled' do
allow_any_instance_of(GeoNode).to receive(:enabled?) { false } allow_any_instance_of(GeoNode).to receive(:enabled?) { false }
expect(Geo::RepositorySyncService).not_to receive(:new) expect(Geo::ProjectSyncWorker).not_to receive(:perform_in)
subject.perform
end
it 'does not perform Geo::RepositorySyncService when can not obtain a lease' do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { false }
expect(Geo::RepositorySyncService).not_to receive(:new)
subject.perform subject.perform
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