This project is archived and is in readonly mode.
Introduce ActiveResource::Base.timeout to allow Net::HTTP#read_timeout to be set
Reported by Cheah Chu Yeow | April 17th, 2008 @ 04:48 AM
Active Resource relies on HTTP to access RESTful APIs and as such is inherently susceptible to slow or unresponsive servers. In such cases, your Active Resource method calls could timeout.
This patch allows you to declare a timeout value like so:
class Person < ActiveResource::Base
self.site = "http://api.people.com:3000/"
self.timeout = 5
end
This sets the timeout to 5 seconds. It is recommended to set this to a reasonably low value to allow your Active Resource clients (especially if you are using Active Resource in a Rails application) to fail-fast (see http://en.wikipedia.org/wiki/Fai...) rather than cause cascading failures that could incapacitate your server.
Internally, Active Resource relies on Ruby's Net::HTTP library to make HTTP requests. Setting timeout sets the read_timeout of the internal Net::HTTP instance to the same value. The default read_timeout is 60 seconds on most Ruby implementations (which ihmo is too long if your ARes call is in a public-facing controller!).
Comments and changes to this ticket
-
Cheah Chu Yeow April 16th, 2008 @ 11:41 AM
Sorry for the bad formatting - the "Formatting help?" link seems broken - go to http://lighthouseapp.com/help/te... for formatting help.
-
Frederick Cheung April 16th, 2008 @ 04:27 PM
class Person < ActiveResource::Base self.site = "http://api.people.com:3000/" self.timeout = 5 end
-
Cheah Chu Yeow April 17th, 2008 @ 03:34 AM
Hehe thanks Frederick. Sorry but I can't edit my original ticket!
-
Cheah Chu Yeow April 18th, 2008 @ 04:05 AM
- Title changed from [PATCH] Introduce ActiveResource::Base.timeout to allow Net::HTTP#read_timeout to be set to Introduce ActiveResource::Base.timeout to allow Net::HTTP#read_timeout to be set
-
Michael Koziarski April 21st, 2008 @ 10:34 PM
- State changed from new to resolved
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 5370 activerecord problem when create with characters with accents or special characters titulo con caracteres especiales intro de la publicaci pr...