2018-05-30 18:16:43 +02:00
|
|
|
class WhoisSyncJob < ApplicationJob
|
|
|
|
queue_as :default
|
|
|
|
|
|
|
|
rescue_from ActiveRecord::RecordNotFound do; end
|
|
|
|
|
|
|
|
attr_reader :check
|
|
|
|
|
|
|
|
def perform(check_id)
|
|
|
|
@check = Check.find(check_id)
|
2018-06-02 15:13:25 +02:00
|
|
|
check.update_attribute(:last_run_at, Time.now)
|
2018-05-30 18:16:43 +02:00
|
|
|
|
2018-06-02 15:13:25 +02:00
|
|
|
response = Whois.ask(check.domain)
|
2018-05-30 18:16:43 +02:00
|
|
|
return unless response.valid?
|
|
|
|
|
|
|
|
update_from_response(response)
|
|
|
|
|
|
|
|
check.save!
|
|
|
|
rescue Whois::DomainNotFoundError
|
|
|
|
check.active = false
|
|
|
|
check.save!
|
2018-06-02 15:13:25 +02:00
|
|
|
rescue Whois::ParserError # rubocop:disable Lint/HandleExceptions
|
|
|
|
# already logged
|
2018-05-30 18:16:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_from_response(response)
|
|
|
|
check.domain_created_at = response.created_at
|
|
|
|
check.domain_updated_at = response.updated_at
|
2018-06-02 17:45:50 +02:00
|
|
|
check.domain_expires_at = response.expire_at
|
2018-06-02 15:13:25 +02:00
|
|
|
check.last_success_at = Time.now
|
2018-05-30 18:16:43 +02:00
|
|
|
end
|
|
|
|
end
|