Commit 34081571 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not override original AR5 batching interface

parent 84d9789d
...@@ -15,7 +15,7 @@ module ActiveRecord ...@@ -15,7 +15,7 @@ module ActiveRecord
relation = relation.where(arel_table[primary_key].lteq(finish)) if finish relation = relation.where(arel_table[primary_key].lteq(finish)) if finish
batch_relation = relation batch_relation = relation
1.step do |index| loop do
if load if load
records = batch_relation.records records = batch_relation.records
ids = records.map(&:id) ids = records.map(&:id)
...@@ -31,7 +31,7 @@ module ActiveRecord ...@@ -31,7 +31,7 @@ module ActiveRecord
primary_key_offset = ids.last primary_key_offset = ids.last
raise ArgumentError.new("Primary key not included in the custom select clause") unless primary_key_offset raise ArgumentError.new("Primary key not included in the custom select clause") unless primary_key_offset
yield yielded_relation, index yield yielded_relation
break if ids.length < of break if ids.length < of
batch_relation = relation.where(arel_table[primary_key].gt(primary_key_offset)) batch_relation = relation.where(arel_table[primary_key].gt(primary_key_offset))
......
...@@ -12,9 +12,12 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration ...@@ -12,9 +12,12 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
end end
def up def up
Build.where(stage_id: nil).in_batches(of: BATCH_SIZE) do |relation, index| index = 1
schedule = index * 5.minutes
Build.where(stage_id: nil).in_batches(of: BATCH_SIZE) do |relation|
jobs = relation.pluck(:id).map { |id| [MIGRATION, [id]] } jobs = relation.pluck(:id).map { |id| [MIGRATION, [id]] }
schedule = index * 5.minutes
index += 1
BackgroundMigrationWorker.perform_bulk_in(schedule, jobs) BackgroundMigrationWorker.perform_bulk_in(schedule, jobs)
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