Schedule background migration only when it is needed

This commit is contained in:
Grzegorz Bizon 2017-06-28 12:23:00 +02:00
parent 02bb40e2ac
commit 5292eb651e
1 changed files with 6 additions and 4 deletions

View File

@ -12,11 +12,13 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
end
def up
Build.find_in_batches(batch_size: BATCH_SIZE).with_index do |builds, batch|
migrations = builds.map { |build| [MIGRATION, [build.id]] }
Build.where(stage_id: nil)
.find_in_batches(batch_size: BATCH_SIZE)
.with_index do |builds, batch|
migrations = builds.map { |build| [MIGRATION, [build.id]] }
BackgroundMigrationWorker.perform_bulk(*migrations)
end
BackgroundMigrationWorker.perform_bulk(*migrations)
end
end
def down