mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 02:35:57 +02:00
Added first version of whois update and sync tasks
This commit is contained in:
parent
e678e655da
commit
fbd7ca3146
2 changed files with 41 additions and 10 deletions
|
@ -53,6 +53,7 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
after_save :manage_automatic_statuses
|
after_save :manage_automatic_statuses
|
||||||
after_save :update_whois_body
|
after_save :update_whois_body
|
||||||
|
after_save :update_whois_server
|
||||||
|
|
||||||
validates :name_dirty, domain_name: true, uniqueness: true
|
validates :name_dirty, domain_name: true, uniqueness: true
|
||||||
validates :period, numericality: { only_integer: true }
|
validates :period, numericality: { only_integer: true }
|
||||||
|
@ -118,6 +119,10 @@ class Domain < ActiveRecord::Base
|
||||||
return period.to_i.months if unit == 'm'
|
return period.to_i.months if unit == 'm'
|
||||||
return period.to_i.years if unit == 'y'
|
return period.to_i.years if unit == 'y'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def included
|
||||||
|
includes(:registrar, :nameservers, {tech_contacts: :registrar}, {admin_contacts: :registrar})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def name=(value)
|
def name=(value)
|
||||||
|
@ -228,12 +233,6 @@ class Domain < ActiveRecord::Base
|
||||||
log
|
log
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_whois_server
|
|
||||||
wd = Whois::Domain.find_or_initialize_by(name: name)
|
|
||||||
wd.whois_body = whois_body
|
|
||||||
wd.save
|
|
||||||
end
|
|
||||||
|
|
||||||
# rubocop:disable Metrics/MethodLength
|
# rubocop:disable Metrics/MethodLength
|
||||||
def update_whois_body
|
def update_whois_body
|
||||||
self.whois_body = <<-EOS
|
self.whois_body = <<-EOS
|
||||||
|
@ -260,14 +259,12 @@ class Domain < ActiveRecord::Base
|
||||||
created: #{registrar.created_at.to_s(:db)}
|
created: #{registrar.created_at.to_s(:db)}
|
||||||
changed: #{registrar.updated_at.to_s(:db)}
|
changed: #{registrar.updated_at.to_s(:db)}
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
update_whois_server
|
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/MethodLength
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
|
||||||
def contacts_body
|
def contacts_body
|
||||||
out = ''
|
out = ''
|
||||||
admin_contacts.includes(:registrar).each do |c|
|
admin_contacts.each do |c|
|
||||||
out << 'Admin contact:'
|
out << 'Admin contact:'
|
||||||
out << "name: #{c.name}"
|
out << "name: #{c.name}"
|
||||||
out << "email: #{c.email}"
|
out << "email: #{c.email}"
|
||||||
|
@ -275,7 +272,7 @@ class Domain < ActiveRecord::Base
|
||||||
out << "created: #{c.created_at.to_s(:db)}"
|
out << "created: #{c.created_at.to_s(:db)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
tech_contacts.includes(:registrar).each do |c|
|
tech_contacts.each do |c|
|
||||||
out << 'Tech contact:'
|
out << 'Tech contact:'
|
||||||
out << "name: #{c.name}"
|
out << "name: #{c.name}"
|
||||||
out << "email: #{c.email}"
|
out << "email: #{c.email}"
|
||||||
|
@ -284,4 +281,10 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_whois_server
|
||||||
|
wd = Whois::Domain.find_or_initialize_by(name: name)
|
||||||
|
wd.whois_body = whois_body
|
||||||
|
wd.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
28
lib/tasks/whois.rake
Normal file
28
lib/tasks/whois.rake
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
namespace :whois do
|
||||||
|
desc 'Regenerate Registry records and sync whois database'
|
||||||
|
task sync_all: :environment do
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Regenerate whois records at Registry master database'
|
||||||
|
task generate: :environment do
|
||||||
|
start = Time.zone.now.to_f
|
||||||
|
print "-----> Update Registry whois records..."
|
||||||
|
Domain.included.find_each(batch_size: 100000).with_index do |d, index|
|
||||||
|
d.update_columns(whois_body: d.update_whois_body)
|
||||||
|
print '.' if index % 100 == 0
|
||||||
|
end
|
||||||
|
puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Sync whois database'
|
||||||
|
task sync: :environment do
|
||||||
|
start = Time.zone.now.to_f
|
||||||
|
print "-----> Sync whois database..."
|
||||||
|
Domain.select(:id, :name, :whois_body).find_each(batch_size: 100000).with_index do |d, index|
|
||||||
|
d.update_whois_server
|
||||||
|
print '.' if index % 100 == 0
|
||||||
|
end
|
||||||
|
puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue