Class: Aspera::TimerLimiter
- Inherits:
-
Object
- Object
- Aspera::TimerLimiter
- Defined in:
- lib/aspera/timer_limiter.rb
Overview
used to throttle logs
Instance Method Summary collapse
-
#initialize(delay) ⇒ TimerLimiter
constructor
A new instance of TimerLimiter.
- #trigger? ⇒ Boolean
Constructor Details
#initialize(delay) ⇒ TimerLimiter
Returns a new instance of TimerLimiter.
7 8 9 10 11 |
# File 'lib/aspera/timer_limiter.rb', line 7 def initialize(delay) @delay = delay @last_time = nil @count = 0 end |
Instance Method Details
#trigger? ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aspera/timer_limiter.rb', line 13 def trigger? old_time = @last_time @last_time = Time.now.to_f @count += 1 if old_time.nil? || ((@last_time - old_time) > @delay) @count = 0 return true end return false end |