BigW Consortium Gitlab

Commit 9a32ca40 by Grzegorz Bizon

Find builds that require a migration in batches

parent b7d67232
...@@ -2,6 +2,8 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration ...@@ -2,6 +2,8 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
DOWNTIME = false DOWNTIME = false
BATCH_SIZE = 10000
MIGRATION = 'MigrateBuildStageIdReference'.freeze
disable_ddl_transaction! disable_ddl_transaction!
...@@ -10,9 +12,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration ...@@ -10,9 +12,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
end end
def up def up
Build.find_each do |build| Build.find_in_batches(batch_size: BATCH_SIZE).with_index do |builds, batch|
BackgroundMigrationWorker migrations = builds.map { |build| [MIGRATION, [build.id]] }
.perform_async('MigrateBuildStageIdReference', [build.id])
BackgroundMigrationWorker.perform_bulk(*migrations)
end end
end end
......
...@@ -8,6 +8,8 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do ...@@ -8,6 +8,8 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
before do before do
stub_const('MigrateStageIdReferenceInBackground::BATCH_SIZE', 1)
projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1') projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1')
pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a') pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a')
......
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