Method: Collective::Monitor#monitor

Defined in:
lib/collective/monitor.rb

#monitorObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/collective/monitor.rb', line 17

def monitor
  status = {}

  job = ->() do
    changed = false
    pools.each do |pool|

      log pool.name
      previous = status[pool.name]
      current  = pool.synchronize log: true

      if previous != current then
        status[pool.name] = current
        changed = true
      end

    end
    changed
  end

  job = Collective::Idler.new( job, min_sleep: 1, max_sleep: 10 )

  ok = true
  trap("TERM") { ok = false }
  while ok do
    job.call
  end
end