File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -235,6 +235,7 @@ class DocsCLI < Thor
235235 puts 'Docs -- BEGIN'
236236
237237 require 'open-uri'
238+ require 'net/http'
238239 require 'thread'
239240
240241 docs = Docs . all_versions
@@ -250,15 +251,30 @@ class DocsCLI < Thor
250251 [ 'index.json' , 'meta.json' ] . each do |filename |
251252 json = "https://documents.devdocs.io/#{ doc . path } /#{ filename } ?#{ time } "
252253 begin
253- URI . open ( json , "Accept-Encoding" => "identity" ) do |file |
254- mutex . synchronize do
255- path = File . join ( dir , filename )
256- File . write ( path , file . read )
254+ attempts = 0
255+
256+ begin
257+ attempts += 1
258+
259+ URI . open ( json , "Accept-Encoding" => "identity" ) do |file |
260+ mutex . synchronize do
261+ path = File . join ( dir , filename )
262+ File . write ( path , file . read )
263+ end
257264 end
265+ rescue Net ::OpenTimeout , Net ::ReadTimeout => e
266+ if attempts <= 3
267+ wait_seconds = 2 **( attempts - 1 )
268+ puts "Docs -- Retrying #{ json } in #{ wait_seconds } s (#{ e . class } : #{ e . message } )"
269+ sleep ( wait_seconds )
270+ retry
271+ end
272+
273+ raise
258274 end
259275 rescue => e
260- puts "Docs -- Failed to download #{ json } !"
261- throw e
276+ puts "Docs -- Failed to download #{ json } after #{ attempts } attempts !"
277+ raise
262278 end
263279 end
264280
You can’t perform that action at this time.
0 commit comments