From a0fcd8be8bbb857f1cb608e0226a51fa6fad6929 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 26 Jan 2016 14:36:09 +0200 Subject: [PATCH] 111297422-job_and_method_update --- app/jobs/update_whois_record_job.rb | 16 +++++++++++----- app/models/blocked_domain.rb | 2 ++ app/models/reserved_domain.rb | 2 ++ lib/tasks/whois.rake | 21 +++++++++++++-------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/jobs/update_whois_record_job.rb b/app/jobs/update_whois_record_job.rb index 39abeeb9c..b7edb1fdd 100644 --- a/app/jobs/update_whois_record_job.rb +++ b/app/jobs/update_whois_record_job.rb @@ -1,10 +1,16 @@ class UpdateWhoisRecordJob < Que::Job - def run(ids, type) - ids.each do |id| - record = WhoisRecord.find_by(id: id) - return unless record - record.save + def run(ids, type) + klass = case type + when 'reserved'then ReservedDomain + when 'blocked' then BlockedDomain + else Domain + end + + ids.each do |id| + record = klass.find_by(id: id) + next unless record + record.update_whois_record end end end \ No newline at end of file diff --git a/app/models/blocked_domain.rb b/app/models/blocked_domain.rb index a25e1ff6a..079926512 100644 --- a/app/models/blocked_domain.rb +++ b/app/models/blocked_domain.rb @@ -24,6 +24,8 @@ class BlockedDomain < ActiveRecord::Base update_whois_server end + alias_method :update_whois_record, :generate_data + def update_whois_server wr = Whois::Record.find_or_initialize_by(name: name) wr.body = @body diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index 141fd7263..d477f2524 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -35,6 +35,8 @@ class ReservedDomain < ActiveRecord::Base update_whois_server end + alias_method :update_whois_record, :generate_data + def update_whois_server wr = Whois::Record.find_or_initialize_by(name: name) wr.body = @body diff --git a/lib/tasks/whois.rake b/lib/tasks/whois.rake index afd4cd62e..c8c3ba2a1 100644 --- a/lib/tasks/whois.rake +++ b/lib/tasks/whois.rake @@ -3,18 +3,23 @@ namespace :whois do task regenerate: :environment do start = Time.zone.now.to_f - @i = 0 print "-----> Regenerate Registry whois_records table and sync with whois server..." ActiveRecord::Base.uncached do - puts "\n#{@i}" - Domain.included.find_in_batches(batch_size: 10000) do |batch| - batch.map(&:update_whois_record) - puts(@i += 10000) - GC.start + + print "\n-----> Update domains whois_records" + Domain.find_in_batches.each do |group| + UpdateWhoisRecordJob.enqueue group.map(&:id), 'domain' end - GC.start - UpdateWhoisRecordJob.enqueue WhoisRecord.find_each.map(&:id), 'domain' + print "\n-----> Update blocked domains whois_records" + BlockedDomain.find_in_batches.each do |group| + UpdateWhoisRecordJob.enqueue group.map(&:id), 'blocked' + end + + print "\n-----> Update reserved domains whois_records" + ReservedDomain.find_in_batches.each do |group| + UpdateWhoisRecordJob.enqueue group.map(&:id), 'reserved' + end end puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"