Commit 82a92801 authored by Kerri Miller's avatar Kerri Miller

Mark completed jobs as successful

This is essentially the same as spec/lib/gitlab/background_migration/backfill_draft_status_on_merge_requests_spec.rb
but with the newly-added helper to mark track_jobs as completed (per
@sabrams in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66788#note_644449984)

Changelog: added
parent baa6067d
# 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 ...@@ -27,6 +27,17 @@ module Gitlab
eligible_mrs.each_slice(10) do |slice| eligible_mrs.each_slice(10) do |slice|
MergeRequest.where(id: slice).update_all(draft: true) MergeRequest.where(id: slice).update_all(draft: true)
end 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 end
end end
......
...@@ -23,6 +23,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests d ...@@ -23,6 +23,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests d
end end
context "for MRs with #draft? == true titles but draft attribute false" do context "for MRs with #draft? == true titles but draft attribute false" do
let(:mr_ids) { merge_requests.all.collect(&:id) }
before do before do
draft_prefixes.each do |prefix| draft_prefixes.each do |prefix|
(1..4).each do |n| (1..4).each do |n|
...@@ -37,11 +39,16 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests d ...@@ -37,11 +39,16 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests d
it "updates all open draft merge request's draft field to true" do it "updates all open draft merge request's draft field to true" do
mr_count = merge_requests.all.count mr_count = merge_requests.all.count
mr_ids = merge_requests.all.collect(&:id)
expect { subject.perform(mr_ids.first, mr_ids.last) } expect { subject.perform(mr_ids.first, mr_ids.last) }
.to change { MergeRequest.where(draft: false).count } .to change { MergeRequest.where(draft: false).count }
.from(mr_count).to(mr_count - draft_prefixes.length) .from(mr_count).to(mr_count - draft_prefixes.length)
end 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
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