mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 08:43:37 +02:00
Story#113066359 - all whois generation of domain and reserved/blocked domain is async + domain destroy removes whois async
This commit is contained in:
parent
ca037092d3
commit
93d765dea2
5 changed files with 66 additions and 47 deletions
|
@ -1,16 +1,52 @@
|
||||||
class UpdateWhoisRecordJob < Que::Job
|
class UpdateWhoisRecordJob < Que::Job
|
||||||
|
|
||||||
def run(ids, type)
|
def run(names, type)
|
||||||
klass = case type
|
klass = case type
|
||||||
when 'reserved'then ReservedDomain
|
when 'reserved'then ReservedDomain
|
||||||
when 'blocked' then BlockedDomain
|
when 'blocked' then BlockedDomain
|
||||||
else Domain
|
when 'domain' then Domain
|
||||||
end
|
end
|
||||||
|
|
||||||
ids.each do |id|
|
Array(names).each do |name|
|
||||||
record = klass.find_by(id: id)
|
record = klass.find_by(name: name)
|
||||||
next unless record
|
if record
|
||||||
record.update_whois_record
|
send "update_#{type}", record
|
||||||
|
else
|
||||||
|
send "delete_#{type}", name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def update_domain(domain)
|
||||||
|
domain.whois_record ? domain.whois_record.save : domain.create_whois_record
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_reserved(record)
|
||||||
|
record.generate_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_blocked(record)
|
||||||
|
update_reserved(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# 1. deleting own
|
||||||
|
# 2. trying to regenerate reserved in order domain is still in the list
|
||||||
|
def delete_domain(name)
|
||||||
|
WhoisRecord.where(name: name).destroy_all
|
||||||
|
|
||||||
|
BlockedDomain.find_by(name: name).try(:generate_data)
|
||||||
|
ReservedDomain.find_by(name: name).try(:generate_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_reserved(name)
|
||||||
|
Domain.where(name: name).any?
|
||||||
|
Whois::Record.where(name: name).delete_all
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_blocked(name)
|
||||||
|
delete_reserved(name)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,8 +1,9 @@
|
||||||
class BlockedDomain < ActiveRecord::Base
|
class BlockedDomain < ActiveRecord::Base
|
||||||
include Versions
|
include Versions
|
||||||
before_save :generate_data
|
before_save :generate_data
|
||||||
before_destroy :remove_data
|
after_destroy :remove_data
|
||||||
validates :name, domain_name: true, uniqueness: true
|
|
||||||
|
validates :name, domain_name: true, uniqueness: true
|
||||||
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -22,19 +23,14 @@ validates :name, domain_name: true, uniqueness: true
|
||||||
def generate_data
|
def generate_data
|
||||||
return if Domain.where(name: name).any?
|
return if Domain.where(name: name).any?
|
||||||
|
|
||||||
@json = generate_json
|
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||||
@body = generate_body
|
wr.json = @json = generate_json # we need @json to bind to class
|
||||||
update_whois_server
|
wr.body = generate_body
|
||||||
|
wr.save
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :update_whois_record, :generate_data
|
alias_method :update_whois_record, :generate_data
|
||||||
|
|
||||||
def update_whois_server
|
|
||||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
|
||||||
wr.body = @body
|
|
||||||
wr.json = @json
|
|
||||||
wr.save
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate_body
|
def generate_body
|
||||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||||
|
@ -49,8 +45,6 @@ validates :name, domain_name: true, uniqueness: true
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_data
|
def remove_data
|
||||||
return if Domain.where(name: name).any?
|
UpdateWhoisRecordJob.enqueue name, 'blocked'
|
||||||
|
|
||||||
Whois::Record.where(name: name).delete_all
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Domain < ActiveRecord::Base
|
||||||
has_many :dnskeys, dependent: :destroy
|
has_many :dnskeys, dependent: :destroy
|
||||||
|
|
||||||
has_many :keyrelays
|
has_many :keyrelays
|
||||||
has_one :whois_record, dependent: :destroy
|
has_one :whois_record # destroyment will be done in after_commit
|
||||||
|
|
||||||
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class Domain < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
after_save :update_whois_record
|
after_commit :update_whois_record
|
||||||
|
|
||||||
after_create :update_reserved_domains
|
after_create :update_reserved_domains
|
||||||
def update_reserved_domains
|
def update_reserved_domains
|
||||||
|
@ -826,7 +826,8 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_whois_record
|
def update_whois_record
|
||||||
whois_record.blank? ? create_whois_record : whois_record.save
|
p "run by transaction"
|
||||||
|
UpdateWhoisRecordJob.enqueue name, 'domain'
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_notes_array=(notes)
|
def status_notes_array=(notes)
|
||||||
|
|
|
@ -2,7 +2,8 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
include Versions # version/reserved_domain_version.rb
|
include Versions # version/reserved_domain_version.rb
|
||||||
before_save :fill_empty_passwords
|
before_save :fill_empty_passwords
|
||||||
before_save :generate_data
|
before_save :generate_data
|
||||||
before_destroy :remove_data
|
after_destroy :remove_data
|
||||||
|
|
||||||
validates :name, domain_name: true, uniqueness: true
|
validates :name, domain_name: true, uniqueness: true
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,12 +26,7 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
def fill_empty_passwords
|
def fill_empty_passwords
|
||||||
|
self.password = SecureRandom.hex if self.password.blank?
|
||||||
if self.password.empty?
|
|
||||||
|
|
||||||
self.password = SecureRandom.hex
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def name= val
|
def name= val
|
||||||
|
@ -40,19 +36,13 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
def generate_data
|
def generate_data
|
||||||
return if Domain.where(name: name).any?
|
return if Domain.where(name: name).any?
|
||||||
|
|
||||||
@json = generate_json
|
|
||||||
@body = generate_body
|
|
||||||
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 = Whois::Record.find_or_initialize_by(name: name)
|
||||||
wr.body = @body
|
wr.json = @json = generate_json # we need @json to bind to class
|
||||||
wr.json = @json
|
wr.body = generate_body
|
||||||
wr.save
|
wr.save
|
||||||
end
|
end
|
||||||
|
alias_method :update_whois_record, :generate_data
|
||||||
|
|
||||||
|
|
||||||
def generate_body
|
def generate_body
|
||||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||||
|
@ -67,9 +57,7 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_data
|
def remove_data
|
||||||
return if Domain.where(name: name).any?
|
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
||||||
|
|
||||||
Whois::Record.where(name: name).delete_all
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,17 +8,17 @@ namespace :whois do
|
||||||
|
|
||||||
print "\n-----> Update domains whois_records"
|
print "\n-----> Update domains whois_records"
|
||||||
Domain.find_in_batches.each do |group|
|
Domain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:id), 'domain'
|
UpdateWhoisRecordJob.enqueue group.map(&:name), 'domain'
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n-----> Update blocked domains whois_records"
|
print "\n-----> Update blocked domains whois_records"
|
||||||
BlockedDomain.find_in_batches.each do |group|
|
BlockedDomain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:id), 'blocked'
|
UpdateWhoisRecordJob.enqueue group.map(&:name), 'blocked'
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n-----> Update reserved domains whois_records"
|
print "\n-----> Update reserved domains whois_records"
|
||||||
ReservedDomain.find_in_batches.each do |group|
|
ReservedDomain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:id), 'reserved'
|
UpdateWhoisRecordJob.enqueue group.map(&:name), 'reserved'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue