Commit dfef5437 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use a helper to schedule pipeline stages migration

parent 2ee20d5a
...@@ -3,7 +3,7 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration ...@@ -3,7 +3,7 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
MIGRATION = 'MigrateBuildStage'.freeze MIGRATION = 'MigrateBuildStage'.freeze
BATCH_SIZE = 800 BATCH_SIZE = 500
disable_ddl_transaction! disable_ddl_transaction!
...@@ -15,10 +15,11 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration ...@@ -15,10 +15,11 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration
def up def up
disable_statement_timeout disable_statement_timeout
Build.where('stage_id IS NULL').each_batch(of: BATCH_SIZE) do |builds, index| Build.where('stage_id IS NULL').tap do |relation|
builds.pluck('MIN(id)', 'MAX(id)').first.tap do |range| queue_background_migration_jobs_by_range_at_intervals(relation,
BackgroundMigrationWorker.perform_in(index * 5.minutes, MIGRATION, range) MIGRATION,
end 5.minutes,
batch_size: BATCH_SIZE)
end end
end end
......
...@@ -35,8 +35,6 @@ module Gitlab ...@@ -35,8 +35,6 @@ module Gitlab
end end
def perform(start_id, stop_id) def perform(start_id, stop_id)
# TODO, statement timeout?
stages = Migratable::Build.where('stage_id IS NULL') stages = Migratable::Build.where('stage_id IS NULL')
.where('id BETWEEN ? AND ?', start_id, stop_id) .where('id BETWEEN ? AND ?', start_id, stop_id)
.map { |build| build.ensure_stage! } .map { |build| build.ensure_stage! }
......
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