Commit d9944061 authored by Jan Provaznik's avatar Jan Provaznik

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
parents 2f311b53 977ba4cc
...@@ -5,6 +5,8 @@ class PagesDomainVerificationCronWorker ...@@ -5,6 +5,8 @@ class PagesDomainVerificationCronWorker
include CronjobQueue include CronjobQueue
def perform def perform
return if Gitlab::Database.read_only?
PagesDomain.needs_verification.find_each do |domain| PagesDomain.needs_verification.find_each do |domain|
PagesDomainVerificationWorker.perform_async(domain.id) PagesDomainVerificationWorker.perform_async(domain.id)
end end
......
...@@ -5,6 +5,8 @@ class PagesDomainVerificationWorker ...@@ -5,6 +5,8 @@ class PagesDomainVerificationWorker
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(domain_id) def perform(domain_id)
return if Gitlab::Database.read_only?
domain = PagesDomain.find_by(id: domain_id) domain = PagesDomain.find_by(id: domain_id)
return unless domain return unless domain
......
...@@ -10,6 +10,13 @@ describe PagesDomainVerificationCronWorker do ...@@ -10,6 +10,13 @@ describe PagesDomainVerificationCronWorker do
let!(:reverify) { create(:pages_domain, :reverify) } let!(:reverify) { create(:pages_domain, :reverify) }
let!(:disabled) { create(:pages_domain, :disabled) } 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 it 'enqueues a PagesDomainVerificationWorker for domains needing verification' do
[reverify, disabled].each do |domain| [reverify, disabled].each do |domain|
expect(PagesDomainVerificationWorker).to receive(:perform_async).with(domain.id) expect(PagesDomainVerificationWorker).to receive(:perform_async).with(domain.id)
......
...@@ -8,6 +8,13 @@ describe PagesDomainVerificationWorker do ...@@ -8,6 +8,13 @@ describe PagesDomainVerificationWorker do
let(:domain) { create(:pages_domain) } let(:domain) { create(:pages_domain) }
describe '#perform' do 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 it 'does nothing for a non-existent domain' do
domain.destroy domain.destroy
......
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