summaryrefslogtreecommitdiff
path: root/db/post_migrate/20190528180441_enqueue_reset_merge_status.rb
blob: 1b668d85bac04f6c2038769b4d9086ee2cd8a4e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class EnqueueResetMergeStatus < ActiveRecord::Migration[5.1]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  BATCH_SIZE = 10_000
  MIGRATION = 'ResetMergeStatus'
  DELAY_INTERVAL = 5.minutes.to_i

  disable_ddl_transaction!

  def up
    say 'Scheduling `ResetMergeStatus` jobs'

    # We currently have around 135_000 opened, mergeable MRs in GitLab.com. This iteration
    # will schedule around 13 batches of 10_000 MRs, which should take around 1 hour to
    # complete.
    relation = MergeRequest.where(state: 'opened', merge_status: 'can_be_merged')

    relation.each_batch(of: BATCH_SIZE) do |batch, index|
      range = batch.pluck('MIN(id)', 'MAX(id)').first

      BackgroundMigrationWorker.perform_in(index * DELAY_INTERVAL, MIGRATION, range)
    end
  end
end