Commit 3fddf612 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-disable-mirrors-for-geo' into 'master'

Disable mirror workers for Geo secondaries

See merge request !1671
parents 4f7c11b4 791064da
......@@ -75,6 +75,7 @@ class RemoteMirror < ActiveRecord::Base
def sync
return unless project && enabled
return if Gitlab::Geo.secondary?
RepositoryUpdateRemoteMirrorWorker.perform_in(BACKOFF_DELAY, self.id, Time.now) if project&.repository_exists?
end
......
......@@ -5,6 +5,9 @@ class UpdateAllMirrorsWorker
LEASE_TIMEOUT = 840
def perform
# This worker requires updating the database state, which we can't
# do on a Geo secondary
return if Gitlab::Geo.secondary?
return unless try_obtain_lease
fail_stuck_mirrors!
......
---
title: Disable mirror workers for Geo secondaries
merge_request:
author:
......@@ -41,11 +41,23 @@ module Gitlab
sync_times
end
def update_all_mirrors_cron_job
Sidekiq::Cron::Job.find("update_all_mirrors_worker")
end
def destroy_cron_job!
update_all_mirrors_cron_job&.destroy
end
def configure_cron_job!
if Gitlab::Geo.secondary?
destroy_cron_job!
return
end
minimum_mirror_sync_time = current_application_settings.minimum_mirror_sync_time rescue FIFTEEN
sync_time = SYNC_TIME_TO_CRON[minimum_mirror_sync_time]
Sidekiq::Cron::Job.find("update_all_mirrors_worker")&.destroy
destroy_cron_job!
Sidekiq::Cron::Job.create(
name: 'update_all_mirrors_worker',
......
......@@ -191,6 +191,19 @@ describe Gitlab::Mirror do
expect(Sidekiq::Cron::Job.find("update_all_mirrors_worker").cron).to eq(fifteen_cron)
end
end
describe 'when Geo is enabled' do
it 'disables mirror cron job' do
described_class.configure_cron_job!
expect(described_class.update_all_mirrors_cron_job).to be_enabled
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
described_class.configure_cron_job!
expect(described_class.update_all_mirrors_cron_job).to be_nil
end
end
end
end
......
......@@ -119,6 +119,14 @@ describe RemoteMirror do
expect(remote_mirror.sync).to be_nil
end
end
context 'as a Geo secondary' do
it 'returns nil' do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
expect(remote_mirror.sync).to be_nil
end
end
end
context '#updated_since?' 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