Class: Collective::Monitor

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/collective/monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#format_for_logging, #log, #logger, #logger=

Constructor Details

#initialize(configuration) ⇒ Monitor

Returns a new instance of Monitor.



10
11
12
13
14
# File 'lib/collective/monitor.rb', line 10

def initialize( configuration )
  @pools = configuration.policies.map do |kind,policy|
    pool = Collective::Pool.new( kind, policy )
  end
end

Instance Attribute Details

#poolsObject (readonly)

Returns the value of attribute pools.



8
9
10
# File 'lib/collective/monitor.rb', line 8

def pools
  @pools
end

Instance Method Details

#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

#restartObject



52
53
54
55
56
# File 'lib/collective/monitor.rb', line 52

def restart
  pools.each do |pool|
    pool.restart
  end
end

#stop_allObject

monitor



46
47
48
49
50
# File 'lib/collective/monitor.rb', line 46

def stop_all
  pools.each do |pool|
    pool.stop_all
  end
end