2019-08-20 13:50:04 +02:00
|
|
|
# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr>
|
|
|
|
# License: GNU AGPL-3+ (see full text in LICENSE file)
|
2019-03-03 10:42:19 +01:00
|
|
|
|
2018-05-30 18:16:43 +02:00
|
|
|
class WhoisSyncJob < ApplicationJob
|
|
|
|
queue_as :default
|
|
|
|
|
2018-06-05 15:25:19 +02:00
|
|
|
rescue_from StandardError do |exception|
|
|
|
|
check_logger.log(:standard_error, exception) if check.present?
|
|
|
|
raise # rubocop:disable Style/SignalException
|
|
|
|
end
|
|
|
|
|
2018-05-30 18:16:43 +02:00
|
|
|
rescue_from ActiveRecord::RecordNotFound do; end
|
|
|
|
|
2018-06-05 15:25:19 +02:00
|
|
|
# parser error are already logged
|
|
|
|
rescue_from Whois::Error do; end
|
|
|
|
|
2018-05-30 18:16:43 +02:00
|
|
|
attr_reader :check
|
|
|
|
|
|
|
|
def perform(check_id)
|
2018-06-05 15:25:19 +02:00
|
|
|
prepare_check(check_id)
|
2018-05-30 18:16:43 +02:00
|
|
|
|
2018-06-05 15:25:19 +02:00
|
|
|
response = Whois.ask(check.domain, logger: check_logger)
|
2018-05-30 18:16:43 +02:00
|
|
|
return unless response.valid?
|
|
|
|
|
|
|
|
update_from_response(response)
|
|
|
|
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-06-05 15:25:19 +02:00
|
|
|
|
|
|
|
check.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prepare_check(check_id)
|
|
|
|
@check = Check.find(check_id)
|
|
|
|
check.update_attribute(:last_run_at, Time.now)
|
|
|
|
end
|
|
|
|
|
|
|
|
# logger is a reserved ActiveJob method
|
|
|
|
def check_logger
|
|
|
|
@check_logger ||= CheckLogger.new(check)
|
2018-05-30 18:16:43 +02:00
|
|
|
end
|
|
|
|
end
|