Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Introduce ActiveResource::Base.timeout to allow Net::HTTP#read_timeout to be set

#5

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!).

Reported by Cheah Chu Yeow · April 17th, 2008 @ 04:48 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Cheah Chu Yeow
    Cheah Chu Yeow

    Sorry for the bad formatting - the "Formatting help?" link seems broken - go to http://lighthouseapp.com/help/te... for formatting help.

    April 16th, 2008 @ 11:41 AM

  2. Matt Baron
    Matt Baron

    Does lighthouse do syntax highlighting?

    April 16th, 2008 @ 01:05 PM

  3. Frederick Cheung
    Frederick Cheung
    class Person < ActiveResource::Base
      self.site = "http://api.people.com:3000/"
      self.timeout = 5
    end
    

    April 16th, 2008 @ 04:27 PM

  4. Frederick Cheung
  5. Cheah Chu Yeow
    Cheah Chu Yeow

    Hehe thanks Frederick. Sorry but I can't edit my original ticket!

    April 17th, 2008 @ 03:34 AM

  6. Cheah Chu Yeow
    Cheah Chu Yeow
    • 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

    April 18th, 2008 @ 04:05 AM

  7. Michael Koziarski
    Michael Koziarski
    • State changed from new to resolved

    April 21st, 2008 @ 10:34 PM