Commit 0036fc6f authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'backstage/gb/improve-stages-statuses-migration' into 'master'

Adjust a range and a batch sizes in stages statuses migration

Closes #36793

See merge request !13767
parents 676f7726 4737fc3b
...@@ -6,7 +6,7 @@ class MigrateStagesStatuses < ActiveRecord::Migration ...@@ -6,7 +6,7 @@ class MigrateStagesStatuses < ActiveRecord::Migration
disable_ddl_transaction! disable_ddl_transaction!
BATCH_SIZE = 10000 BATCH_SIZE = 10000
RANGE_SIZE = 1000 RANGE_SIZE = 100
MIGRATION = 'MigrateStageStatus'.freeze MIGRATION = 'MigrateStageStatus'.freeze
class Stage < ActiveRecord::Base class Stage < ActiveRecord::Base
...@@ -17,10 +17,10 @@ class MigrateStagesStatuses < ActiveRecord::Migration ...@@ -17,10 +17,10 @@ class MigrateStagesStatuses < ActiveRecord::Migration
def up def up
Stage.where(status: nil).each_batch(of: BATCH_SIZE) do |relation, index| Stage.where(status: nil).each_batch(of: BATCH_SIZE) do |relation, index|
relation.each_batch(of: RANGE_SIZE) do |batch| relation.each_batch(of: RANGE_SIZE) do |batch|
range = relation.pluck('MIN(id)', 'MAX(id)').first range = batch.pluck('MIN(id)', 'MAX(id)').first
schedule = index * 5.minutes delay = index * 5.minutes
BackgroundMigrationWorker.perform_in(schedule, MIGRATION, range) BackgroundMigrationWorker.perform_in(delay, MIGRATION, range)
end end
end end
end end
......
...@@ -12,7 +12,7 @@ describe MigrateStagesStatuses, :migration do ...@@ -12,7 +12,7 @@ describe MigrateStagesStatuses, :migration do
before do before do
stub_const("#{described_class.name}::BATCH_SIZE", 2) stub_const("#{described_class.name}::BATCH_SIZE", 2)
stub_const("#{described_class.name}::RANGE_SIZE", 2) stub_const("#{described_class.name}::RANGE_SIZE", 1)
projects.create!(id: 1, name: 'gitlab1', path: 'gitlab1') projects.create!(id: 1, name: 'gitlab1', path: 'gitlab1')
projects.create!(id: 2, name: 'gitlab2', path: 'gitlab2') projects.create!(id: 2, name: 'gitlab2', path: 'gitlab2')
...@@ -50,9 +50,10 @@ describe MigrateStagesStatuses, :migration do ...@@ -50,9 +50,10 @@ describe MigrateStagesStatuses, :migration do
Timecop.freeze do Timecop.freeze do
migrate! migrate!
expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 1, 2) expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 1, 1)
expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 2, 2)
expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, 3, 3) expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, 3, 3)
expect(BackgroundMigrationWorker.jobs.size).to eq 2 expect(BackgroundMigrationWorker.jobs.size).to eq 3
end end
end end
end end
......
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