active_resource_throttle

所属分类:WEB开发
开发工具:Ruby
文件大小:7KB
下载次数:0
上传日期:2009-05-07 15:32:56
上 传 者sh-1993
说明:  ActiveResource请求的节流器。
(A throttler for ActiveResource requests.)

文件列表:
HISTORY (41, 2009-05-07)
LICENSE (1309, 2009-05-07)
Rakefile (308, 2009-05-07)
active_resource_throttle.gemspec (872, 2009-05-07)
lib (0, 2009-05-07)
lib\active_resource_throttle.rb (4764, 2009-05-07)
lib\active_resource_throttle (0, 2009-05-07)
lib\active_resource_throttle\hash_ext.rb (502, 2009-05-07)
test (0, 2009-05-07)
test\active_resource_throttle_test.rb (3574, 2009-05-07)

= ActiveResource Throttle A rate limiter for ActiveResource requests. == DESCRIPTION: ===Problem 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. ===Solution 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. ==INSTALL: gem sources -a http://gems.github.com gem install aiaio-active_resource_throttle == USAGE: require "active_resource_throttle" class MyResource < ActiveResource::Base include ActiveResourceThrottle self.site = "http://example.com/api/" throttle(:interval => 60, :requests => 20, :sleep_interval => 10) end 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. == ISSUES: 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.

近期下载者

相关文件


收藏者