Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby rest-client: make it never timeout?

I am trying to use ruby rest-client to upload a large number of images to a site that I'm writing. My code looks like:

RestClient.post url, :timeout => 90000000, :open_timeout => 90000000, :file_param => file_obj

However, I am getting this error:

RestClient::RequestTimeout: Request Timeout
    from /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:174:in `transmit'
    from /Library/Ruby/

But when I look at the server log

Completed in 61493ms (View: 2, DB: 1) | 201 Created 

So there doesn't appear to be any reason why this is timing out. Anyone have any idea if there is a timeout param I am not correctly setting?

Thanks

like image 694
earnold Avatar asked Dec 14 '10 03:12

earnold


2 Answers

This syntax sets the timeout as request header (see RestClient.post signature), if you want to use the timeout parameter you must use:

RestClient::Request.execute(:method => :post, :url => @url, :timeout => 90000000)

see: https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L12

like image 130
phlipper Avatar answered Sep 19 '22 17:09

phlipper


Looking at the docs, you can pass -1 through RestClient.execute timeout param:

# * :timeout and :open_timeout passing in -1 will disable the timeout by setting the corresponding net timeout values to nil

It can be used as follows:

resource = RestClient::Resource.new(
  "url",
  :timeout => -1,
  :open_timeout => -1
response = resource.get :params => {<params>}
like image 42
clemensp Avatar answered Sep 17 '22 17:09

clemensp