我正在将Rails应用程序从Rails 4.2升级到5,从Ruby 2.2.3升级到2.3.3。我们使用的一个delayed_job进程缓存来自Web上其他地方的图像。缓存的图像通过s3支持的回形针存储,但似乎它是间歇性失败的读取 - 每个作业运行缓存大约40-60个图像,具有适当的限制,因此缓存不会使服务器沉没,大约80数据的各个部分的总作业运行 - 每个作业开始,缓存一些图像,然后用下面的堆栈跟踪炸毁。
值得注意的是:
任何建议表示赞赏。堆栈跟踪指向第1041行,这是开放(URI.parse ...)行,而不是file.write行,所以我认为将图像缓存,而不是将其写入s3是一个问题。
def image_from_url(url, type)
file = Tempfile.new("tmp_image_"+type+[*1..10000].sample.to_s+".jpg")
file.binmode
encoded_url = URI.encode(url)
open(URI.parse(encoded_url)) do |data|
file.write data.read
end
file.rewind
if type == "profile"
self.profile_picture = file
else
self.main_picture = file
end
end
堆栈跟踪:
Net::OpenTimeout: execution expired
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:880:in `initialize'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:880:in `open'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:319:in `open_http'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:737:in `buffer_open'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:212:in `block in open_loop'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:210:in `catch'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:210:in `open_loop'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:151:in `open_uri'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:717:in `open'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:31:in `open'
from /home/user/public_html/.../apps/.../releases/20161221214252/app/models/base_ad.rb:1041:in `image_from_url'