Commit 721f11de authored by Thong Kuah's avatar Thong Kuah

Merge branch 'pb-fix-ci-batched-bg-worker' into 'master'

Fix batched bg migration for missing ci model

See merge request gitlab-org/gitlab!82127
parents ee8cdca2 7fae3b61
...@@ -31,6 +31,15 @@ module Database ...@@ -31,6 +31,15 @@ module Database
end end
def perform def perform
unless base_model
Sidekiq.logger.info(
class: self.class.name,
database: self.class.tracking_database,
message: 'skipping migration execution for unconfigured database')
return
end
Gitlab::Database::SharedModel.using_connection(base_model.connection) do Gitlab::Database::SharedModel.using_connection(base_model.connection) do
break unless Feature.enabled?(:execute_batched_migrations_on_schedule, type: :ops, default_enabled: :yaml) && active_migration break unless Feature.enabled?(:execute_batched_migrations_on_schedule, type: :ops, default_enabled: :yaml) && active_migration
......
...@@ -42,6 +42,38 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d ...@@ -42,6 +42,38 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d
describe '#perform' do describe '#perform' do
subject(:worker) { described_class.new } subject(:worker) { described_class.new }
context 'when the base model does not exist' do
before do
if Gitlab::Database.has_config?(tracking_database)
skip "because the base model for #{tracking_database} exists"
end
end
it 'does nothing' do
expect(worker).not_to receive(:active_migration)
expect(worker).not_to receive(:run_active_migration)
expect { worker.perform }.not_to raise_error
end
it 'logs a message indicating execution is skipped' do
expect(Sidekiq.logger).to receive(:info) do |payload|
expect(payload[:class]).to eq(described_class.name)
expect(payload[:database]).to eq(tracking_database)
expect(payload[:message]).to match(/skipping migration execution/)
end
expect { worker.perform }.not_to raise_error
end
end
context 'when the base model does exist' do
before do
unless Gitlab::Database.has_config?(tracking_database)
skip "because the base model for #{tracking_database} does not exist"
end
end
context 'when the feature flag is disabled' do context 'when the feature flag is disabled' do
before do before do
stub_feature_flags(execute_batched_migrations_on_schedule: false) stub_feature_flags(execute_batched_migrations_on_schedule: false)
...@@ -162,4 +194,5 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d ...@@ -162,4 +194,5 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d
end end
end end
end end
end
end end
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Database::BatchedBackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state, if: Gitlab::Database.has_config?(:ci) do RSpec.describe Database::BatchedBackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state do
it_behaves_like 'it runs batched background migration jobs', 'ci' it_behaves_like 'it runs batched background migration jobs', 'ci'
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