【发布时间】:2011-11-27 10:25:24
【问题描述】:
要生成离线报告,我的 Rails 应用需要从 Google Charts API 下载图表。
问题:它大部分时间都可以正常工作,但有时(随机)它会失败并显示getaddrinfo: Name or service not known
当我收到错误时,我只是重新启动生成,通常它会成功。
平常吗?是否有防止这种情况的最佳做法?
可能是重入算法,还是更高级的方法?
当前代码:
require 'net/http'
charts.each_with_index do |path, index|
Net::HTTP.start("chart.googleapis.com") do |http|
resp = http.get(path)
open("tmp/charts/chart" + index.to_s + ".png" ,"wb") do |file|
file.write(resp.body)
end
end
end
【问题讨论】: