class HttpThreshold::Client

Public Class Methods

cache() click to toggle source
# File lib/http_threshold/client.rb, line 11
def cache
  @cache ||= Cache.new
end
incr_count(domain) click to toggle source
# File lib/http_threshold/client.rb, line 19
def incr_count(domain)
  self.throttles[domain].try(:incr_count)
end
lock_manager() click to toggle source
# 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 = {}) click to toggle source
# File lib/http_threshold/client.rb, line 23
def set_throttle(domain, options = {})
  self.throttles[domain] = HttpThreshold::Throttle.new(domain, options)
end
sleep_until_allowed(host) { || ... } click to toggle source
# 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() click to toggle source
# File lib/http_threshold/client.rb, line 7
def throttles
  @throttles  ||= {}
end