diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-02-13 16:18:09 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-02-13 16:18:09 +0100 |
commit | 8488c98e70561c6d7dde025131c15df4692b20b1 (patch) | |
tree | 7e8007ad912a0df724a3bce90ff71119b526fe0c /db | |
parent | acc70f7da1c21071a11bb07b86486c8e61799be8 (diff) | |
download | gitlab-ce-8488c98e70561c6d7dde025131c15df4692b20b1.tar.gz |
Schedule pipeline stages migration every 5 minutes
[ci skip]
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20180212101928_schedule_build_stage_migration.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/db/post_migrate/20180212101928_schedule_build_stage_migration.rb b/db/post_migrate/20180212101928_schedule_build_stage_migration.rb index b33127140bb..f03a3f8d355 100644 --- a/db/post_migrate/20180212101928_schedule_build_stage_migration.rb +++ b/db/post_migrate/20180212101928_schedule_build_stage_migration.rb @@ -3,18 +3,26 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration DOWNTIME = false MIGRATION = 'MigrateBuildStage'.freeze - BATCH = 1000 + BATCH_SIZE = 500 + + disable_ddl_transaction! class Build < ActiveRecord::Base include EachBatch self.table_name = 'ci_builds' end - def change - Build.where('stage_id IS NULL').each_batch(of: BATCH) do |builds, index| - builds.pluck(:id).map { |id| [MIGRATION, [id]] }.tap do |migrations| - BackgroundMigrationWorker.bulk_perform_in(index.minutes, migrations) + def up + disable_statement_timeout + + Build.where('stage_id IS NULL').each_batch(of: BATCH_SIZE) do |builds, index| + builds.pluck('MIN(id)', 'MAX(id)').first.tap do |range| + BackgroundMigrationWorker.perform_in(index * 5.minutes, MIGRATION, range) end end end + + def down + # noop + end end |