Commit 69b0252b authored by Vitali Tatarintev's avatar Vitali Tatarintev

Remove MergeRequestAssigneesMigrationProgressCheck background migration

Removes an old background mutation
parent 56d95d9a
# frozen_string_literal: true
class ScheduleMergeRequestAssigneesMigrationProgressCheck < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
MIGRATION = 'MergeRequestAssigneesMigrationProgressCheck'
DOWNTIME = false
disable_ddl_transaction!
def up
BackgroundMigrationWorker.perform_async(MIGRATION)
end
def down
end
end
f655a3f9f1f41710ae501c3e4ef0893791c28971d87e12f87d4b65131502b812
\ No newline at end of file
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
# rubocop: disable Style/Documentation
class MergeRequestAssigneesMigrationProgressCheck
include Gitlab::Utils::StrongMemoize
RESCHEDULE_DELAY = 3.hours
WORKER = 'PopulateMergeRequestAssigneesTable'
DeadJobsError = Class.new(StandardError)
def perform
raise DeadJobsError, "Only dead background jobs in the queue for #{WORKER}" if !ongoing? && dead_jobs?
if ongoing?
BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, self.class.name)
else
Feature.enable(:multiple_merge_request_assignees)
end
end
private
def dead_jobs?
strong_memoize(:dead_jobs) do
migration_klass.dead_jobs?(WORKER)
end
end
def ongoing?
strong_memoize(:ongoing) do
migration_klass.exists?(WORKER) || migration_klass.retrying_jobs?(WORKER)
end
end
def migration_klass
Gitlab::BackgroundMigration
end
end
# rubocop: enable Style/Documentation
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::MergeRequestAssigneesMigrationProgressCheck do
context 'rescheduling' do
context 'when there are ongoing and no dead jobs' do
it 'reschedules check' do
allow(Gitlab::BackgroundMigration).to receive(:exists?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(true)
allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(false)
expect(BackgroundMigrationWorker).to receive(:perform_in).with(described_class::RESCHEDULE_DELAY, described_class.name)
described_class.new.perform
end
end
context 'when there are ongoing and dead jobs' do
it 'reschedules check' do
allow(Gitlab::BackgroundMigration).to receive(:exists?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(true)
allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(true)
expect(BackgroundMigrationWorker).to receive(:perform_in).with(described_class::RESCHEDULE_DELAY, described_class.name)
described_class.new.perform
end
end
context 'when there retrying jobs and no scheduled' do
it 'reschedules check' do
allow(Gitlab::BackgroundMigration).to receive(:exists?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(false)
allow(Gitlab::BackgroundMigration).to receive(:retrying_jobs?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(true)
expect(BackgroundMigrationWorker).to receive(:perform_in).with(described_class::RESCHEDULE_DELAY, described_class.name)
described_class.new.perform
end
end
end
context 'when there are no scheduled, or retrying or dead' do
before do
stub_feature_flags(multiple_merge_request_assignees: false)
end
it 'enables feature' do
allow(Gitlab::BackgroundMigration).to receive(:exists?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(false)
allow(Gitlab::BackgroundMigration).to receive(:retrying_jobs?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(false)
allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(false)
described_class.new.perform
expect(Feature.enabled?(:multiple_merge_request_assignees, type: :licensed)).to eq(true)
end
end
context 'when there are only dead jobs' do
it 'raises DeadJobsError error' do
allow(Gitlab::BackgroundMigration).to receive(:exists?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(false)
allow(Gitlab::BackgroundMigration).to receive(:retrying_jobs?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(false)
allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
.with('PopulateMergeRequestAssigneesTable')
.and_return(true)
expect { described_class.new.perform }
.to raise_error(described_class::DeadJobsError,
"Only dead background jobs in the queue for #{described_class::WORKER}")
end
end
end
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20190402224749_schedule_merge_request_assignees_migration_progress_check.rb')
RSpec.describe ScheduleMergeRequestAssigneesMigrationProgressCheck do
describe '#up' do
it 'schedules MergeRequestAssigneesMigrationProgressCheck background job' do
expect(BackgroundMigrationWorker).to receive(:perform_async)
.with(described_class::MIGRATION)
.and_call_original
subject.up
end
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