Class: Aspera::TimerLimiter

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/timer_limiter.rb

Overview

used to throttle logs

Instance Method Summary collapse

Constructor Details

#initialize(delay) ⇒ TimerLimiter

Returns a new instance of TimerLimiter.

Parameters:

  • delay

    in seconds (float)



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

Returns:

  • (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