【发布时间】:2014-07-02 19:26:49
【问题描述】:
我用https://github.com/ollieglass/share-counter
我的脚本
posts.each do |pp|
begin
puts pp.post_link
url = URI.parse("#{pp.post_link}")
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)
if res.code == "200"
shared_social_count = ShareCounter.all "#{pp.post_link}"
unless shared_social_count.blank?
sd = SharedCount.find_or_create_by post_id: "#{pp.id}"
sd.twitter = shared_social_count[:twitter]
sd.facebook = shared_social_count[:facebook]
sd.linkedin = shared_social_count[:linkedin]
sd.googleplus = shared_social_count[:googleplus]
sd.save
end
end
rescue Exception => e
puts "caught exception #{e}! ohnoes!"
next
end
end
运行良好一段时间,但一些消息导致错误并停止循环
http://www.prnoticias.com/index.php/comunicacion/1224-foro-mundial/20130612-la-asesora-del-papa-tambien-estara-en-la-wprf-
Failed 1 attempt(s) - 504 Gateway Timeout
Failed 2 attempt(s) - 504 Gateway Timeout
Failed 3 attempt(s) - 504 Gateway Timeout
rake aborted!
Exception: Exception
RestClient::GatewayTimeout: 504 Gateway Timeout
知道如何避免不停止循环吗?
【问题讨论】:
标签: ruby-on-rails ruby exception ruby-on-rails-4 timeout