Class: Hive::Monitor

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/hive/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.



9
10
11
12
13
# File 'lib/hive/monitor.rb', line 9

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

Instance Attribute Details

#poolsObject (readonly)

Returns the value of attribute pools.



7
8
9
# File 'lib/hive/monitor.rb', line 7

def pools
  @pools
end

Instance Method Details

#monitorObject



16
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
# File 'lib/hive/monitor.rb', line 16

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 = Hive::Idler.new( job, min_sleep: 1, max_sleep: 10 )

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

#restartObject



51
52
53
54
55
# File 'lib/hive/monitor.rb', line 51

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

#stop_allObject

monitor



45
46
47
48
49
# File 'lib/hive/monitor.rb', line 45

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