要生成离线报告,我的 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