Class: Collective::Monitor
- Inherits:
-
Object
- Object
- Collective::Monitor
- Includes:
- Log
- Defined in:
- lib/collective/monitor.rb
Instance Attribute Summary collapse
-
#pools ⇒ Object
readonly
Returns the value of attribute pools.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Monitor
constructor
A new instance of Monitor.
- #monitor ⇒ Object
- #restart ⇒ Object
-
#stop_all ⇒ Object
monitor.
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
#pools ⇒ Object (readonly)
Returns the value of attribute pools.
8 9 10 |
# File 'lib/collective/monitor.rb', line 8 def pools @pools end |
Instance Method Details
#monitor ⇒ Object
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 |
#restart ⇒ Object
52 53 54 55 56 |
# File 'lib/collective/monitor.rb', line 52 def restart pools.each do |pool| pool.restart end end |
#stop_all ⇒ Object
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 |