From 97bf1464db70e27fa40aa6ee186dfbfd4c32259d Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Sat, 8 Jun 2024 10:46:49 +0200 Subject: aesan: 3 tries --- aesan_alerts.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aesan_alerts.rb b/aesan_alerts.rb index 675c047..85db083 100755 --- a/aesan_alerts.rb +++ b/aesan_alerts.rb @@ -26,7 +26,17 @@ def read_title(file_path, line) end def fetch_first_paragraph(url) - response = Net::HTTP.get_response(URI.parse(url)) + response = nil + error = nil + (1..3).each do + response = Net::HTTP.get_response(URI.parse(url)) + break + rescue StandardError => error + sleep 5 + end + if response.nil? + abort "Error al descargar URL tras 3 intentos: #{error}" + end if response.is_a?(Net::HTTPSuccess) document = Nokogiri::HTML(response.body) @@ -45,7 +55,7 @@ def fetch_first_paragraph(url) puts ps end else - warn "Error al descargar página: #{response.code} #{response.message}" + abort "Error al descargar página: #{response.code} #{response.message}" end end -- cgit v1.2.3