Class: BugCourier::RateLimiter
- Inherits:
-
Object
- Object
- BugCourier::RateLimiter
- Defined in:
- lib/bug_courier/exception_handler.rb
Instance Method Summary collapse
- #allow? ⇒ Boolean
-
#initialize(max_per_hour:) ⇒ RateLimiter
constructor
A new instance of RateLimiter.
Constructor Details
#initialize(max_per_hour:) ⇒ RateLimiter
7 8 9 10 11 |
# File 'lib/bug_courier/exception_handler.rb', line 7 def initialize(max_per_hour:) @max_per_hour = max_per_hour = [] @mutex = Mutex.new end |
Instance Method Details
#allow? ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bug_courier/exception_handler.rb', line 13 def allow? @mutex.synchronize do now = Time.now .reject! { |t| now - t > 3600 } return false if .size >= @max_per_hour << now true end end |