Commit 45badbe3 authored by Steve Abrams's avatar Steve Abrams

Merge branch '333947-rerun-background-migration-with-new-error-tracking' into 'master'

Mark completed jobs as successful

See merge request gitlab-org/gitlab!67687
parents f30a5d19 82a92801
# frozen_string_literal: true
class ScheduleBackfillDraftColumnOnMergeRequestsRerun < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
MIGRATION = 'BackfillDraftStatusOnMergeRequests'
DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 50
disable_ddl_transaction!
def up
eligible_mrs = Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests::MergeRequest.eligible
queue_background_migration_jobs_by_range_at_intervals(
eligible_mrs,
MIGRATION,
DELAY_INTERVAL,
track_jobs: true,
batch_size: BATCH_SIZE
)
end
def down
# noop
#
end
end
e4f4f3c91cdb8ce8b1fa6c2bd0bb1fb1a8c0dedbb78c20bbaef6e36bfa9551c4
\ No newline at end of file
......@@ -27,6 +27,17 @@ module Gitlab
eligible_mrs.each_slice(10) do |slice|
MergeRequest.where(id: slice).update_all(draft: true)
end
mark_job_as_succeeded(start_id, end_id)
end
private
def mark_job_as_succeeded(*arguments)
Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded(
'BackfillDraftStatusOnMergeRequests',
arguments
)
end
end
end
......
......@@ -23,6 +23,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests d
end
context "for MRs with #draft? == true titles but draft attribute false" do
let(:mr_ids) { merge_requests.all.collect(&:id) }
before do
draft_prefixes.each do |prefix|
(1..4).each do |n|
......@@ -37,11 +39,16 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests d
it "updates all open draft merge request's draft field to true" do
mr_count = merge_requests.all.count
mr_ids = merge_requests.all.collect(&:id)
expect { subject.perform(mr_ids.first, mr_ids.last) }
.to change { MergeRequest.where(draft: false).count }
.from(mr_count).to(mr_count - draft_prefixes.length)
end
it "marks successful slices as completed" do
expect(subject).to receive(:mark_job_as_succeeded).with(mr_ids.first, mr_ids.last)
subject.perform(mr_ids.first, mr_ids.last)
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