mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
111297422-job_and_method_update
This commit is contained in:
parent
8ed8a46046
commit
a0fcd8be8b
4 changed files with 28 additions and 13 deletions
|
@ -1,10 +1,16 @@
|
||||||
class UpdateWhoisRecordJob < Que::Job
|
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
|
end
|
||||||
end
|
end
|
|
@ -24,6 +24,8 @@ class BlockedDomain < ActiveRecord::Base
|
||||||
update_whois_server
|
update_whois_server
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :update_whois_record, :generate_data
|
||||||
|
|
||||||
def update_whois_server
|
def update_whois_server
|
||||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||||
wr.body = @body
|
wr.body = @body
|
||||||
|
|
|
@ -35,6 +35,8 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
update_whois_server
|
update_whois_server
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :update_whois_record, :generate_data
|
||||||
|
|
||||||
def update_whois_server
|
def update_whois_server
|
||||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||||
wr.body = @body
|
wr.body = @body
|
||||||
|
|
|
@ -3,18 +3,23 @@ namespace :whois do
|
||||||
task regenerate: :environment do
|
task regenerate: :environment do
|
||||||
start = Time.zone.now.to_f
|
start = Time.zone.now.to_f
|
||||||
|
|
||||||
@i = 0
|
|
||||||
print "-----> Regenerate Registry whois_records table and sync with whois server..."
|
print "-----> Regenerate Registry whois_records table and sync with whois server..."
|
||||||
ActiveRecord::Base.uncached do
|
ActiveRecord::Base.uncached do
|
||||||
puts "\n#{@i}"
|
|
||||||
Domain.included.find_in_batches(batch_size: 10000) do |batch|
|
print "\n-----> Update domains whois_records"
|
||||||
batch.map(&:update_whois_record)
|
Domain.find_in_batches.each do |group|
|
||||||
puts(@i += 10000)
|
UpdateWhoisRecordJob.enqueue group.map(&:id), 'domain'
|
||||||
GC.start
|
|
||||||
end
|
end
|
||||||
|
|
||||||
GC.start
|
print "\n-----> Update blocked domains whois_records"
|
||||||
UpdateWhoisRecordJob.enqueue WhoisRecord.find_each.map(&:id), 'domain'
|
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
|
end
|
||||||
puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue