Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set timeout in RestClient gem in Ruby?

I am using RestClient gem by making get call to the server through it. The question is how do I set the timeout from client side.

RestClient.get "http://127.0.0.1:7819/tokenize/word/stackoverflow"

I want to set it to 10 seconds.

Thanks in Advance!!

like image 562
sravan_kumar Avatar asked May 07 '12 13:05

sravan_kumar


1 Answers

You don't need to monkey patch anything. You can use RestClient::Request directly, like:

RestClient::Request.execute(:method => :get, :url => url, :timeout => 10, :open_timeout => 10)

But remember the worst case scenario is 20 seconds.

Check the other post answer https://stackoverflow.com/a/5445421/565999

like image 51
Hugo Tavares Avatar answered Oct 10 '22 08:10

Hugo Tavares