Module: ActiveResourceThrottle::ClassMethods
- Includes:
- ClassInheritableAttributes
- Defined in:
- lib/active_resource_throttle.rb
Instance Method Summary collapse
-
#connection_with_throttle(refresh = false) ⇒ Object
Interrupts connection requests only if throttle is engaged.
-
#request_history ⇒ Object
Getter method for request history.
-
#sleep_interval ⇒ Object
Getter method for sleep interval.
-
#throttle(options = {}) ⇒ Object
Sets throttling options for the given class and all subclasses.
-
#throttle_interval ⇒ Object
Getter method for throttle interval.
-
#throttle_request_limit ⇒ Object
Getter method for throttle request limit.
Methods included from ClassInheritableAttributes
#cattr_inheritable, #inherited
Instance Method Details
#connection_with_throttle(refresh = false) ⇒ Object
Interrupts connection requests only if throttle is engaged.
74 75 76 77 |
# File 'lib/active_resource_throttle.rb', line 74 def connection_with_throttle(refresh = false) throttle_connection_request if throttle_engaged? && base_class? connection_without_throttle(refresh) end |
#request_history ⇒ Object
Getter method for request history.
Person.request_history # => [Tue Dec 16 17:35:01 UTC 2008, Tue Dec 16 17:35:03 UTC 2008]
52 53 54 |
# File 'lib/active_resource_throttle.rb', line 52 def request_history @request_history end |
#sleep_interval ⇒ Object
Getter method for sleep interval.
Person.sleep_interval # => 15
34 35 36 |
# File 'lib/active_resource_throttle.rb', line 34 def sleep_interval @sleep_interval end |
#throttle(options = {}) ⇒ Object
Sets throttling options for the given class and all subclasses.
class Person < ActiveResource::Base
throttle(:interval => 60, :requests => 15, :sleep_interval => 10)
end
Note that the sleep_interval argument is optional. It will default to 5 seconds if not specified.
63 64 65 66 67 68 69 70 |
# File 'lib/active_resource_throttle.rb', line 63 def throttle(={}) .assert_valid_keys(:interval, :requests, :sleep_interval) .assert_required_keys(:interval, :requests) @throttle_interval = [:interval] @throttle_request_limit = [:requests] @sleep_interval = [:sleep_interval] || 5 @request_history = [] end |
#throttle_interval ⇒ Object
Getter method for throttle interval.
Person.throttle_interval # => 60
40 41 42 |
# File 'lib/active_resource_throttle.rb', line 40 def throttle_interval @throttle_interval end |
#throttle_request_limit ⇒ Object
Getter method for throttle request limit.
Person.throttle_request_limit # => 10
46 47 48 |
# File 'lib/active_resource_throttle.rb', line 46 def throttle_request_limit @throttle_request_limit end |