Class: HttpThreshold::Client
- Inherits:
-
Object
- Object
- HttpThreshold::Client
- Defined in:
- lib/http_threshold/client.rb
Class Method Summary collapse
- .cache ⇒ Object
- .incr_count(domain) ⇒ Object
- .lock_manager ⇒ Object
- .set_throttle(domain, options = {}) ⇒ Object
- .sleep_until_allowed(host) ⇒ Object
- .throttles ⇒ Object
Class Method Details
.cache ⇒ Object
11 12 13 |
# File 'lib/http_threshold/client.rb', line 11 def cache @cache ||= Cache.new end |
.incr_count(domain) ⇒ Object
19 20 21 |
# File 'lib/http_threshold/client.rb', line 19 def incr_count(domain) self.throttles[domain].try(:incr_count) end |
.lock_manager ⇒ Object
15 16 17 |
# File 'lib/http_threshold/client.rb', line 15 def lock_manager @lock_manager ||= Redlock::Client.new([Redis.new(:url => HttpThreshold.redis_url)]) end |
.set_throttle(domain, options = {}) ⇒ Object
23 24 25 |
# File 'lib/http_threshold/client.rb', line 23 def set_throttle(domain, = {}) self.throttles[domain] = HttpThreshold::Throttle.new(domain, ) end |
.sleep_until_allowed(host) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/http_threshold/client.rb', line 27 def sleep_until_allowed(host) throttle = self.throttles[host] if throttle if !throttle.incr_count puts "#{host} reach threshold limit" sleep 0.25 while !throttle.incr_count sleep 0.25 end end yield else yield end end |
.throttles ⇒ Object
7 8 9 |
# File 'lib/http_threshold/client.rb', line 7 def throttles @throttles ||= {} end |