Method: TinyRl#initialize
- Defined in:
- lib/tiny_rl.rb
#initialize(limit, per, strategy) ⇒ TinyRl
rate: number of requests per unit time per: unit of time (one of SECOND, MINUTE, etc.)
you can pass any integer in as the `per' parameter and it will be
interpreted as a number of seconds
strategy: what to do when you’re over the rate limit
drop: drop the request, never perform the method call
error: raise an exception when rate exceeded
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tiny_rl.rb', line 46 def initialize(limit, per, strategy) raise TinyRlInvalidStrategyError.new("Strategy `#{strategy.inspect}' is not one of the allowed strategies") unless STRATEGIES.include?(strategy) @total_jobs = 0 @dropped_jobs = 0 @errored_jobs = 0 @limit = limit @per = per @strategy = strategy @job_call_times = [] end |