嗨,我正在使用HTTPClient gem,但是我遇到了问题。我将其用于用户注册。在运行时,用户名和密码已插入到我的数据库中,但是等待很长时间然后返回给我
HTTP Client::ReceiveTimeout Error in User Controller#signup execution expired.
我该如何解决我的问题?
最佳答案
我猜您的http连接或远程连接不稳定。
每当遇到这种情况时,我都会使用超时并重试几次。
以下代码将执行您的代码10秒钟,如果未完成,它将超时并重试。如果重试多次失败,则最终将失败。
def timeout_and_retry
retries = 0
begin
Timeout::timeout(10) { yield }
rescue Timeout::Error
raise if (self.retries += 1) > 3
retry
end
end
timeout_and_retry do
# http client get code goes here
end
关于ruby-on-rails - Ruby on Rails中的HTTPClient::ReceiveTimeoutError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10013037/