Add logging & domain lock on release

This commit is contained in:
Alex Sherman 2021-01-05 14:58:01 +05:00
parent d35042a1be
commit 0c5ef72c7d
5 changed files with 30 additions and 3 deletions

View file

@ -39,9 +39,12 @@ module Concerns
def release def release
if release_to_auction if release_to_auction
transaction do with_lock do
to_stdout "Checking if domain_name is auctionable: #{domain_name.auctionable?}"
domain_name.sell_at_auction if domain_name.auctionable? domain_name.sell_at_auction if domain_name.auctionable?
to_stdout 'Destroying domain'
destroy! destroy!
to_stdout 'Sending registrar notification'
registrar.notifications.create!(text: "#{I18n.t(:domain_deleted)}: #{name}", registrar.notifications.create!(text: "#{I18n.t(:domain_deleted)}: #{name}",
attached_obj_id: id, attached_obj_id: id,
attached_obj_type: self.class) attached_obj_type: self.class)
@ -50,6 +53,11 @@ module Concerns
discard discard
end end
end end
def to_stdout(message)
time = Time.zone.now.utc
STDOUT << "#{time} - #{message}\n" unless Rails.env.test?
end
end end
end end
end end

View file

@ -0,0 +1,8 @@
module ToStdout
extend ActiveSupport::Concern
def to_stdout(message)
time = Time.zone.now.utc
STDOUT << "#{time} - #{message}\n" unless Rails.env.test?
end
end

View file

@ -2,6 +2,7 @@ module DNS
# Namespace is needed, because a class with the same name is defined by `domain_name` gem, # Namespace is needed, because a class with the same name is defined by `domain_name` gem,
# a dependency of `actionmailer`, # a dependency of `actionmailer`,
class DomainName class DomainName
include ToStdout
def initialize(name) def initialize(name)
@name = name @name = name
end end
@ -36,6 +37,7 @@ module DNS
auction = Auction.new auction = Auction.new
auction.domain = name auction.domain = name
auction.start auction.start
to_stdout "Created the auction: #{auction.inspect}"
update_whois_from_auction(auction) update_whois_from_auction(auction)
end end
@ -100,7 +102,8 @@ module DNS
whois_record = Whois::Record.find_or_create_by!(name: name) do |record| whois_record = Whois::Record.find_or_create_by!(name: name) do |record|
record.json = {} record.json = {}
end end
to_stdout "Starting to update WHOIS record #{whois_record.inspect}\n\n"\
"from auction #{auction.inspect}"
whois_record.update_from_auction(auction) whois_record.update_from_auction(auction)
end end
end end

View file

@ -1,24 +1,30 @@
module Whois module Whois
class Record < Whois::Server class Record < Whois::Server
include ToStdout
self.table_name = 'whois_records' self.table_name = 'whois_records'
def self.disclaimer def self.disclaimer
Setting.registry_whois_disclaimer Setting.registry_whois_disclaimer
end end
# rubocop:disable Metrics/AbcSize
def update_from_auction(auction) def update_from_auction(auction)
if auction.started? if auction.started?
update!(json: { name: auction.domain, update!(json: { name: auction.domain,
status: ['AtAuction'], status: ['AtAuction'],
disclaimer: self.class.disclaimer }) disclaimer: self.class.disclaimer })
to_stdout "Updated from auction WHOIS record #{inspect}"
elsif auction.no_bids? elsif auction.no_bids?
to_stdout "Destroying WHOIS record #{inspect}"
destroy! destroy!
elsif auction.awaiting_payment? || auction.payment_received? elsif auction.awaiting_payment? || auction.payment_received?
update!(json: { name: auction.domain, update!(json: { name: auction.domain,
status: ['PendingRegistration'], status: ['PendingRegistration'],
disclaimer: self.class.disclaimer, disclaimer: self.class.disclaimer,
registration_deadline: auction.whois_deadline }) registration_deadline: auction.whois_deadline })
to_stdout "Updated from auction WHOIS record #{inspect}"
end end
end end
# rubocop:enable Metrics/AbcSize
end end
end end

View file

@ -25,6 +25,7 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
def test_skips_auction_when_domains_is_blocked def test_skips_auction_when_domains_is_blocked
assert_equal 'shop.test', @domain.name assert_equal 'shop.test', @domain.name
blocked_domains(:one).update!(name: 'shop.test') blocked_domains(:one).update!(name: 'shop.test')
@domain.save!(validate: false)
@domain.release @domain.release
@ -34,6 +35,7 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
def test_skips_auction_when_domains_is_reserved def test_skips_auction_when_domains_is_reserved
assert_equal 'shop.test', @domain.name assert_equal 'shop.test', @domain.name
reserved_domains(:one).update!(name: 'shop.test') reserved_domains(:one).update!(name: 'shop.test')
@domain.save!(validate: false)
@domain.release @domain.release
@ -58,7 +60,7 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
end end
end end
def test_updates_whois def test_updates_whois_server
@domain.update!(delete_date: '2010-07-04') @domain.update!(delete_date: '2010-07-04')
travel_to Time.zone.parse('2010-07-05') travel_to Time.zone.parse('2010-07-05')