Commit fc73f551 authored by Mark Chao's avatar Mark Chao

Update progress checker

Check presence of type of jobs in queue
parent d3458463
...@@ -6,35 +6,17 @@ module Gitlab ...@@ -6,35 +6,17 @@ module Gitlab
RESCHEDULE_DELAY = 1.day RESCHEDULE_DELAY = 1.day
def perform def perform
if remaining('MergeRequest') == 0 && remaining('Project') == 0 if remaining?
Feature.enable(:approval_rule)
else
BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, self.class.name) BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, self.class.name)
else
Feature.enable(:approval_rule)
end end
end end
private private
def remaining(class_name) def remaining?
target_type = ActiveRecord::Base.connection.quote(class_name) Gitlab::BackgroundMigration.exists?('MigrateApproverToApprovalRulesInBatch')
sql_old_schema = <<-SQL.strip_heredoc
SELECT count(*) FROM (
SELECT target_id FROM "approvers" WHERE "approvers"."target_type" = #{target_type}
UNION
SELECT target_id FROM "approver_groups" WHERE "approver_groups"."target_type" = #{target_type}
) AS target_count
SQL
sql_new_schema = <<-SQL.strip_heredoc
SELECT count(distinct #{class_name.foreign_key}) from approval_#{class_name.underscore}_rules
SQL
count(sql_old_schema) - count(sql_new_schema)
end
def count(sql)
ActiveRecord::Base.connection.exec_query(sql).first['count']
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRulesCheckProgress do
context 'when there is MigrateApproverToApprovalRulesInBatch jobs' do
it 'reschedules check' do
allow(Gitlab::BackgroundMigration).to receive(:exists?).with('MigrateApproverToApprovalRulesInBatch').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 is no more MigrateApproverToApprovalRulesInBatch jobs' do
it 'enables feature' do
allow(Gitlab::BackgroundMigration).to receive(:exists?).with('MigrateApproverToApprovalRulesInBatch').and_return(false)
expect(Feature).to receive(:enable).and_return(:approval_rule)
described_class.new.perform
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