Class: KnocKnoc::WatchmanMonitor

Inherits:
Watchman
  • Object
show all
Defined in:
lib/knoc-knoc/watchman_monitor.rb

Constant Summary

Constants inherited from Watchman

KnocKnoc::Watchman::SUBNET

Instance Attribute Summary

Attributes inherited from Watchman

#whos_left, #whos_new, #whos_there

Instance Method Summary collapse

Methods inherited from Watchman

local_ip, ping, ping_all, #refresh_lists, #update_new_ips, #update_whos_left

Constructor Details

#initializeWatchmanMonitor

Returns a new instance of WatchmanMonitor.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/knoc-knoc/watchman_monitor.rb', line 5

def initialize
  super
  @running = true
  #run the refresh_lists once before 
  #starting the set interval
  Thread.new() do 
    self.refresh_lists
    self.repeat_every(30) do 
      self.refresh_lists
    end
  end
end

Instance Method Details

#cleanupObject



27
28
29
# File 'lib/knoc-knoc/watchman_monitor.rb', line 27

def cleanup
  @running = false
end

#repeat_every(interval, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/knoc-knoc/watchman_monitor.rb', line 18

def repeat_every(interval, &block)
  while @running 
    start_time = Time.now
    Thread.new(&block).join
    elapsed = Time.now - start_time
    sleep([interval - elapsed, 0].max)
  end
end