Class: Chokepoint::Minute

Inherits:
TimeWindow show all
Defined in:
lib/chokepoint/minute.rb

Overview

This rate limiter strategy throttles the block by defining a maximum number of allowed calls per minute (by default, 60 requests per minute, which works out to an average of 1 request per second).

Note that this strategy doesn’t use a sliding time window, but rather tracks calls per distinct minute. This means that the throttling counter is reset every minute.

Examples:

Allowing up to 60 requests/minute

Chokepoint::Minute.new('activity').throttle do ... end

Allowing up to 100 requests per minute

Chokepoint::Minute.new('activity', :max => 100).throttle do ... end

Instance Attribute Summary

Attributes inherited from Limiter

#name, #options

Instance Method Summary collapse

Methods inherited from TimeWindow

#allowed?

Methods inherited from Limiter

#allowed?, #blacklisted?, #throttle, #whitelisted?

Constructor Details

#initialize(name, options = {}) ⇒ Minute

Returns a new instance of Minute.

Parameters:

  • name (String)
  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :max (Integer) — default: 60


23
24
25
# File 'lib/chokepoint/minute.rb', line 23

def initialize(name, options = {})
  super 
end

Instance Method Details

#max_per_minuteObject Also known as: max_per_window



28
29
30
# File 'lib/chokepoint/minute.rb', line 28

def max_per_minute
  @max_per_hour ||= options[:max] || 60
end