Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I increase timeout for HTTParty post method in rails?

I have a method in rails to send post requests to a third party API. The code looks similar to the following:

data = HTTParty.post("url",
  :headers=> {'Content-Type' => 'application/json'},
  :body=> { update => true, first_name => "name" }
)

With this, after exactly one minute, the process is terminated with the following error.

<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>
like image 548
Gopi Raju Avatar asked Dec 14 '22 16:12

Gopi Raju


1 Answers

Set the default by:

module HTTParty
  default_timeout your_preferred_timeout
end

or set it individually by:

data = HTTParty.post("url",
  headers: {"Content-Type" => "application/json"},
  body: {update => true, first_name => "name"},
  timeout: your_preferred_timeout
)
like image 111
sawa Avatar answered Dec 28 '22 22:12

sawa