1
要生成离线报告,我的Rails应用程序需要从Google Charts API下载图表。http.get随机地说“getaddrinfo:名称或服务未知”
问题:它正常工作的大部分时间,但有时(随机)失败,并说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
这样可以避免错误,而且速度更快!谢谢! –