Class: Heartbeat::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/tools/heartbeat.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(cycle_length_seconds) ⇒ Monitor

Returns a new instance of Monitor.



67
68
69
70
71
72
73
# File 'lib/tools/heartbeat.rb', line 67

def initialize(cycle_length_seconds)
  @history = History.new(15 * 60 / cycle_length_seconds + 1)
  @cycle_length_seconds = cycle_length_seconds

  @count = 0
  @started_at = Time.now
end

Instance Method Details

#measureObject



75
76
77
78
# File 'lib/tools/heartbeat.rb', line 75

def measure
  @count += 1
  take_measurement
end

#sleepObject



80
81
82
83
# File 'lib/tools/heartbeat.rb', line 80

def sleep
  sleep_time = (@started_at + @count * @cycle_length_seconds) - Time.now
  Kernel.sleep sleep_time if sleep_time > 0
end