internetee-registry/app/jobs/domain_update_confirm_job.rb
2018-08-23 20:03:03 +03:00

37 lines
1.4 KiB
Ruby

class DomainUpdateConfirmJob < Que::Job
def run(domain_id, action, initiator = nil)
::PaperTrail.whodunnit = "job - #{self.class.name} - #{action} by #{initiator}"
# it's recommended to keep transaction against job table as short as possible.
ActiveRecord::Base.transaction do
domain = Epp::Domain.find(domain_id)
domain.is_admin = true
case action
when RegistrantVerification::CONFIRMED
old_registrant = domain.registrant
domain.notify_registrar(:poll_pending_update_confirmed_by_registrant)
raise_errors!(domain)
domain.apply_pending_update!
raise_errors!(domain)
domain.clean_pendings!
raise_errors!(domain)
RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
when RegistrantVerification::REJECTED
RegistrantChangeMailer.rejected(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant).deliver_now
domain.notify_registrar(:poll_pending_update_rejected_by_registrant)
domain.preclean_pendings
domain.clean_pendings!
end
destroy # it's best to destroy the job in the same transaction
end
end
def raise_errors!(domain)
throw "domain #{domain.name} failed with errors #{domain.errors.full_messages}" if domain.errors.any?
end
end