Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions lib/tasks/docs.thor
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class DocsCLI < Thor
puts 'Docs -- BEGIN'

require 'open-uri'
require 'net/http'
require 'thread'

docs = Docs.all_versions
Expand All @@ -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

Expand Down
Loading