2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-29 12:58:38 +02:00
|
|
|
class ProcedureExternalURLCheckJob < ApplicationJob
|
|
|
|
def perform(procedure)
|
|
|
|
procedure.validate
|
|
|
|
|
|
|
|
if procedure.lien_notice.present?
|
|
|
|
error = procedure.errors.find { _1.attribute == :lien_notice }
|
2024-01-29 15:42:35 +01:00
|
|
|
|
|
|
|
procedure.lien_notice_error = check_for_error(error, procedure.lien_notice)
|
|
|
|
procedure.save!(validate: false) # others errors may prevent save if validate
|
2023-06-29 12:58:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if procedure.lien_dpo.present? && !procedure.lien_dpo_email?
|
|
|
|
error = procedure.errors.find { _1.attribute == :lien_dpo }
|
2024-01-29 15:42:35 +01:00
|
|
|
|
|
|
|
procedure.lien_dpo_error = check_for_error(error, procedure.lien_dpo)
|
|
|
|
procedure.save!(validate: false)
|
2023-06-29 12:58:38 +02:00
|
|
|
end
|
|
|
|
end
|
2024-01-29 15:42:35 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_for_error(error, url)
|
|
|
|
return error.message if error.present?
|
|
|
|
|
|
|
|
response = Typhoeus.get(url, followlocation: true)
|
|
|
|
|
|
|
|
return if response.success?
|
|
|
|
|
|
|
|
"#{response.code} #{response.return_message}"
|
|
|
|
end
|
2023-06-29 12:58:38 +02:00
|
|
|
end
|