From fb2fb06cf13383e07decad845da33ba4bc98cc7a Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Tue, 26 May 2026 11:04:44 +0200 Subject: [PATCH] fix: retry failed downloads --- lib/tasks/docs.thor | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/tasks/docs.thor b/lib/tasks/docs.thor index 8dc32d85a9..aef72ed267 100644 --- a/lib/tasks/docs.thor +++ b/lib/tasks/docs.thor @@ -235,6 +235,7 @@ class DocsCLI < Thor puts 'Docs -- BEGIN' require 'open-uri' + require 'net/http' require 'thread' docs = Docs.all_versions @@ -250,15 +251,30 @@ class DocsCLI < Thor ['index.json', 'meta.json'].each do |filename| json = "https://documents.devdocs.io/#{doc.path}/#{filename}?#{time}" begin - URI.open(json, "Accept-Encoding" => "identity") do |file| - mutex.synchronize do - path = File.join(dir, filename) - File.write(path, file.read) + attempts = 0 + + begin + attempts += 1 + + URI.open(json, "Accept-Encoding" => "identity") do |file| + mutex.synchronize do + path = File.join(dir, filename) + File.write(path, file.read) + end end + rescue Net::OpenTimeout, Net::ReadTimeout => e + if attempts <= 3 + wait_seconds = 2**(attempts - 1) + puts "Docs -- Retrying #{json} in #{wait_seconds}s (#{e.class}: #{e.message})" + sleep(wait_seconds) + retry + end + + raise end rescue => e - puts "Docs -- Failed to download #{json}!" - throw e + puts "Docs -- Failed to download #{json} after #{attempts} attempts!" + raise end end