Story#105664240 Regenerate registrar whois records async

This commit is contained in:
Vladimir Krylov 2015-10-28 08:35:08 +02:00
parent a3272fab43
commit 69a9a11588
3 changed files with 22 additions and 2 deletions

View file

@ -0,0 +1,10 @@
class RegenerateRegistrarWhoisesJob < Que::Job
def run(registrar_id)
# no return as we want restart job if fails
registrar = Registrar.find(registrar_id)
registrar.whois_records.select(:id).find_in_batches(batch_size: 20) do |group|
RegenerateWhoisRecordJob.enqueue group.map(&:id)
end
end
end

View file

@ -0,0 +1,10 @@
class RegenerateWhoisRecordJob < Que::Job
def run(ids)
ids.each do |id|
record = WhoisRecord.find_by(id: id)
return unless record
record.save
end
end
end

View file

@ -51,10 +51,10 @@ class Registrar < ActiveRecord::Base
WHOIS_TRIGGERS = %w(name email phone street city state zip)
after_save :update_whois_records
after_commit :update_whois_records
def update_whois_records
return true unless changed? && (changes.keys & WHOIS_TRIGGERS).present?
whois_records.map(&:save) # slow currently
RegenerateRegistrarWhoisesJob.enqueue id
end
after_create :create_cash_account