gpt4 book ai didi

ruby-on-rails - 在 Ruby/Rails 中自定义 IO 流超时值

转载 作者:太空宇宙 更新时间:2023-11-03 18:21:19 25 4
gpt4 key购买 nike

在我的 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 分钟,但是如何以及在哪里?

最佳答案

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

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

所有选项均已记录 here .

关于ruby-on-rails - 在 Ruby/Rails 中自定义 IO 流超时值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17908277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com