我知道 Http.rb 和 Celluloid[1] 目前不支持当前的超时,但是有临时解决方法吗?
这是我要运行的代码:
def fetch(url, options = {} )
puts "Request -> #{url}"
begin
options = options.merge({ socket_class: Celluloid::IO::TCPSocket,
timeout_class: HTTP::Timeout::Global,
timeout_options: {
connect_timeout: 1,
read_timeout: 1,
write_timeout: 1
}
})
HTTP.get(url, options)
rescue HTTP::TimeoutError => e
[do more stuff]
end
end
它的目标是测试服务器是否正常运行。我愿意接受替代品(例如%x(ping <server>)
),但这些似乎效率较低,实际上能够得到我正在寻找的东西。