1

在我的 Rails 应用程序中,我open-uri用来打开一个外部文件,加载时间可能长达 10 分钟

例子:

dl_stream = open('http://wetten.overheid.nl/xml.php?regelingID=bwbr0020368')

现在,1 分钟后,Ruby 会抛出超时错误。我从源代码中收集到了这个,在\net\protocol.rc

@read_timeout = 60

def rbuf_fill
  begin
    @rbuf << @io.read_nonblock(BUFSIZE)
  rescue IO::WaitReadable
    if IO.select([@io], nil, nil, @read_timeout)
      retry
    else
      raise Timeout::Error
    end
  rescue IO::WaitWritable
    # OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
    # http://www.openssl.org/support/faq.html#PROG10
    if IO.select(nil, [@io], nil, @read_timeout)
      retry
    else
      raise Timeout::Error
    end
  end
end

我猜我可以在我的应用程序设置中将此超时值设置为更适合我的情况的值,例如 15 分钟,但是如何以及在哪里呢?

4

1 回答 1

3

您可以open使用以下:read_timeout选项将超时(以秒为单位)添加到调用中:

# timeout after 10 minutes
open('http://example.com', :read_timeout => 600).read

所有选项都记录在这里

于 2013-07-28T12:48:41.817 回答