【发布时间】:2013-09-05 14:29:18
【问题描述】:
目前,Typhoeus 没有在失败时自动重新下载。如果下载不成功,确保重试的最佳方法是什么?
def request
request ||= Typhoeus::Request.new("www.example.com")
request.on_complete do |response|
if response.success?
xml = Nokogiri::XML(response.body)
else
# retry to download it
end
end
end
【问题讨论】:
-
理想情况下,重试逻辑应包括最大重试次数(如@the-tin-man 提到的)、退避策略(例如指数退避)以及指定要执行哪些状态代码的方法重试(无需重试 4xx 错误)。