111297422-job_and_method_update

This commit is contained in:
Stas 2016-01-26 14:36:09 +02:00
parent 8ed8a46046
commit a0fcd8be8b
4 changed files with 28 additions and 13 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"