Class: Lightspeed::RequestThrottler
- Inherits:
-
Object
- Object
- Lightspeed::RequestThrottler
- Defined in:
- lib/lightspeed/request_throttler.rb
Instance Attribute Summary collapse
-
#bucket_level ⇒ Object
Returns the value of attribute bucket_level.
-
#bucket_max ⇒ Object
Returns the value of attribute bucket_max.
-
#units_per_second ⇒ Object
Returns the value of attribute units_per_second.
Instance Method Summary collapse
-
#initialize ⇒ RequestThrottler
constructor
A new instance of RequestThrottler.
- #perform_request(request) ⇒ Object
Constructor Details
#initialize ⇒ RequestThrottler
Returns a new instance of RequestThrottler.
5 6 7 8 9 |
# File 'lib/lightspeed/request_throttler.rb', line 5 def initialize @units_per_second = 0.5 @bucket_max = Float::INFINITY @bucket_level = 0 end |
Instance Attribute Details
#bucket_level ⇒ Object
Returns the value of attribute bucket_level.
3 4 5 |
# File 'lib/lightspeed/request_throttler.rb', line 3 def bucket_level @bucket_level end |
#bucket_max ⇒ Object
Returns the value of attribute bucket_max.
3 4 5 |
# File 'lib/lightspeed/request_throttler.rb', line 3 def bucket_max @bucket_max end |
#units_per_second ⇒ Object
Returns the value of attribute units_per_second.
3 4 5 |
# File 'lib/lightspeed/request_throttler.rb', line 3 def units_per_second @units_per_second end |
Instance Method Details
#perform_request(request) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/lightspeed/request_throttler.rb', line 11 def perform_request request u = units request sleep(u / @units_per_second) if @bucket_level + u > @bucket_max response = request.perform extract_rate_limits request response end |