Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A throttler for ActiveResource requests.

tree: 80867c5fdc

Fetching latest commit…

Cannot retrieve the latest commit at this time


ActiveResource Throttle

A rate limiter for ActiveResource requests.



You're writing a library to consume a RESTful web service. That service publishes a throttle limit. So you need to throttle your requests to prevent the dreaded 503.


ActiveResource Throttle adds request throttling to ActiveResource. Specify the limits in your ActiveResource base class, and no longer will your client code have to worry about the number and frequency of its requests.


gem sources -a
gem install aiaio-active_resource_throttle


require "active_resource_throttle"

class MyResource < ActiveResource::Base
  include ActiveResourceThrottle = "" 
  throttle(:interval => 60, :requests => 20, :sleep_interval => 10)

class Person < MyResource; end
class Post < MyResource; end
  1. Require activeresource_throttle.

  2. Include ActiveResourceThrottle in the ActiveResource class. If you're creating a library to access several resources, it's necessary to create a generic base class for the api you're accessing. Specify the site, login credentials, and throttle, and then subclass the base class for the various resources. Note that the throttle will work across subclasses.

  3. Invoke the #throttle class method with the required options interval and requests. You may also specify a sleep_interval. The settings in the example code above will allow for a maximum of 20 requests per minute. When that limit is reached, requests will be paused for 10 seconds.


ActiveResource Throttle will not work properly across multiple instances of ActiveResource (e.g., in a Rails application with more than one Mongrel). At the moment, it should be used in single-process scripts. Also, the gem is not yet threadsafe.

Expect a threadsafe release in future versions.

Something went wrong with that request. Please try again.