lib/nanoc/extra/checking/checks/external_links.rb in nanoc-3.7.3 vs lib/nanoc/extra/checking/checks/external_links.rb in nanoc-3.7.4
- old
+ new
@@ -69,15 +69,16 @@
10.times do
threads << Thread.new do
loop do
href = enum.next
break if href.nil?
+
res = validate(href)
- if res
- mutex.synchronize do
- invalid << res
- end
+ next unless res
+
+ mutex.synchronize do
+ invalid << res
end
end
end
end
threads.each { |t| t.join }
@@ -97,20 +98,23 @@
# Skip non-HTTP URLs
return nil if url.scheme !~ /^https?$/
# Get status
res = nil
+ last_err = nil
+ timeouts = [3, 5, 10, 30, 60]
5.times do |i|
begin
- Timeout.timeout(10) do
+ Timeout.timeout(timeouts[i]) do
res = request_url_once(url)
if res.code == '405'
res = request_url_once(url, Net::HTTP::Get)
end
end
rescue => e
- return Result.new(href, e.message)
+ last_err = e
+ next # can not allow
end
if res.code =~ /^3..$/
if i == 4
return Result.new(href, 'too many redirects')
@@ -131,10 +135,14 @@
return nil
else
return Result.new(href, res.code)
end
end
- raise 'should not have gotten here'
+ if last_err
+ return Result.new(href, last_err.message)
+ else
+ raise 'should not have gotten here'
+ end
end
def path_for_url(url)
if url.path.nil? || url.path.empty?
path = '/'