Merge pull request #10322 from tchak/chore-backfill-stable-id-custom-limit
chore(task): backfill stable_id with custom limit
This commit is contained in:
commit
bde496b739
2 changed files with 6 additions and 5 deletions
|
@ -1,18 +1,18 @@
|
|||
class Migrations::BackfillStableIdJob < ApplicationJob
|
||||
queue_as :low_priority
|
||||
|
||||
BATCH = 100_000
|
||||
DEFAULT_LIMIT = 50_000
|
||||
|
||||
def perform(iteration)
|
||||
def perform(iteration, limit = DEFAULT_LIMIT)
|
||||
sql = "UPDATE champs SET stable_id = t.stable_id, stream = 'main'
|
||||
FROM types_de_champ t
|
||||
WHERE champs.type_de_champ_id = t.id
|
||||
AND champs.id IN (SELECT id FROM champs WHERE champs.stable_id IS NULL LIMIT ?);"
|
||||
query = ActiveRecord::Base.sanitize_sql_array([sql, BATCH])
|
||||
query = ActiveRecord::Base.sanitize_sql_array([sql, limit])
|
||||
ActiveRecord::Base.connection.execute(query)
|
||||
|
||||
if Champ.exists?(stable_id: nil)
|
||||
Migrations::BackfillStableIdJob.set(wait: 2.seconds).perform_later(iteration + 1)
|
||||
Migrations::BackfillStableIdJob.set(wait: 2.seconds).perform_later(iteration + 1, limit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
module Maintenance
|
||||
class BackfillChampsStableIdTask < MaintenanceTasks::Task
|
||||
attribute :limit, :integer
|
||||
no_collection
|
||||
|
||||
def process
|
||||
Migrations::BackfillStableIdJob.perform_later(0)
|
||||
Migrations::BackfillStableIdJob.perform_later(0, limit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue