Class: Kuroko2::MemoryConsumptionLog::Interval

Inherits:
Object
  • Object
show all
Defined in:
app/models/kuroko2/memory_consumption_log.rb

Overview

As count becames greater, the interval period will be longer. First interval will be 1 second and next interval will be 1 second too, then next interval will be 4 seconds then next interval will be 9 seconds. Finally, maximum of interval will be 30 minutes.

Constant Summary collapse

INITIAL_INTERVAL_PERIOD =
1.second.to_i
MAX_INTERVAL_PERIOD =
30.minutes.to_i
INCREMENT =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_time, count = 0) ⇒ Interval

Returns a new instance of Interval.

Parameters:

  • base_time (Time)
  • count (Integer) (defaults to: 0)

    Throttled to be less than 50.



21
22
23
24
# File 'app/models/kuroko2/memory_consumption_log.rb', line 21

def initialize(base_time, count = 0)
  @base_time = base_time
  @count = [count, 50].min
end

Instance Attribute Details

#base_timeObject (readonly)

Returns the value of attribute base_time.



17
18
19
# File 'app/models/kuroko2/memory_consumption_log.rb', line 17

def base_time
  @base_time
end

#countObject (readonly)

Returns the value of attribute count.



17
18
19
# File 'app/models/kuroko2/memory_consumption_log.rb', line 17

def count
  @count
end

Instance Method Details

#nextMemoryConsumptionLog::Interval



33
34
35
# File 'app/models/kuroko2/memory_consumption_log.rb', line 33

def next
  self.class.new(Time.at(@base_time.to_i + current_length), @count.succ)
end

#reached?(now) ⇒ Boolean

Parameters:

  • now (Time)

Returns:

  • (Boolean)


28
29
30
# File 'app/models/kuroko2/memory_consumption_log.rb', line 28

def reached?(now)
  (now - @base_time) > current_length
end