diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-06-05 12:02:52 +0000 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2019-06-05 12:02:52 +0000 |
commit | d994406192ecb00e6c3b470e9ce99a2ba537cea0 (patch) | |
tree | 2ee171e4c1fea50e8e03fd1f18d6716356670a49 | |
parent | 2f311b532b163d372c4d39e81d2d0a85500de393 (diff) | |
parent | 977ba4cc150092107944f3a46734b2540d321dcf (diff) | |
download | gitlab-ce-d994406192ecb00e6c3b470e9ce99a2ba537cea0.tar.gz |
Merge branch '11925-geo-sidekiq-nodes-try-to-run-jobs-even-thought-db-is-readonly' into 'master'
Ensure DB is writable before continuing jobs
See merge request gitlab-org/gitlab-ce!29134
4 files changed, 18 insertions, 0 deletions
diff --git a/app/workers/pages_domain_verification_cron_worker.rb b/app/workers/pages_domain_verification_cron_worker.rb index 92d62a15aee..60703c83e9e 100644 --- a/app/workers/pages_domain_verification_cron_worker.rb +++ b/app/workers/pages_domain_verification_cron_worker.rb @@ -5,6 +5,8 @@ class PagesDomainVerificationCronWorker include CronjobQueue def perform + return if Gitlab::Database.read_only? + PagesDomain.needs_verification.find_each do |domain| PagesDomainVerificationWorker.perform_async(domain.id) end diff --git a/app/workers/pages_domain_verification_worker.rb b/app/workers/pages_domain_verification_worker.rb index b3319ff5a13..7817b2ee5fc 100644 --- a/app/workers/pages_domain_verification_worker.rb +++ b/app/workers/pages_domain_verification_worker.rb @@ -5,6 +5,8 @@ class PagesDomainVerificationWorker # rubocop: disable CodeReuse/ActiveRecord def perform(domain_id) + return if Gitlab::Database.read_only? + domain = PagesDomain.find_by(id: domain_id) return unless domain diff --git a/spec/workers/pages_domain_verification_cron_worker_spec.rb b/spec/workers/pages_domain_verification_cron_worker_spec.rb index 186824a444f..3fb86adee11 100644 --- a/spec/workers/pages_domain_verification_cron_worker_spec.rb +++ b/spec/workers/pages_domain_verification_cron_worker_spec.rb @@ -10,6 +10,13 @@ describe PagesDomainVerificationCronWorker do let!(:reverify) { create(:pages_domain, :reverify) } let!(:disabled) { create(:pages_domain, :disabled) } + it 'does nothing if the database is read-only' do + allow(Gitlab::Database).to receive(:read_only?).and_return(true) + expect(PagesDomainVerificationWorker).not_to receive(:perform_async).with(reverify.id) + + worker.perform + end + it 'enqueues a PagesDomainVerificationWorker for domains needing verification' do [reverify, disabled].each do |domain| expect(PagesDomainVerificationWorker).to receive(:perform_async).with(domain.id) diff --git a/spec/workers/pages_domain_verification_worker_spec.rb b/spec/workers/pages_domain_verification_worker_spec.rb index 2f23dcb487f..f51ac1f4323 100644 --- a/spec/workers/pages_domain_verification_worker_spec.rb +++ b/spec/workers/pages_domain_verification_worker_spec.rb @@ -8,6 +8,13 @@ describe PagesDomainVerificationWorker do let(:domain) { create(:pages_domain) } describe '#perform' do + it 'does nothing if the database is read-only' do + allow(Gitlab::Database).to receive(:read_only?).and_return(true) + expect(PagesDomain).not_to receive(:find_by).with(id: domain.id) + + worker.perform(domain.id) + end + it 'does nothing for a non-existent domain' do domain.destroy |