[英]How can I increase timeout for HTTParty post method in rails?
我在 rails 中有一個方法可以將 post 請求發送到第三方 API。 該代碼類似於以下內容:
data = HTTParty.post("url",
:headers=> {'Content-Type' => 'application/json'},
:body=> { update => true, first_name => "name" }
)
這樣,一分鍾后,該過程將因以下錯誤而終止。
<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>
設置默認值:
module HTTParty
default_timeout your_preferred_timeout
end
或者單獨設置:
data = HTTParty.post("url",
headers: {"Content-Type" => "application/json"},
body: {update => true, first_name => "name"},
timeout: your_preferred_timeout
)
你可以試試
data = HTTParty.post("url",
headers: {"Content-Type" => "application/json"},
body: {update => true, first_name => "name"},
open_timeout: 0.5,
write_timeout:1,
read_timeout:3
)
你也可以參考
https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#attribute-i-write_timeout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.