Class: Delayed::Master::Monitoring
- Inherits:
-
Object
- Object
- Delayed::Master::Monitoring
- Includes:
- Sleep
- Defined in:
- lib/delayed/master/monitoring.rb
Instance Method Summary collapse
-
#initialize(master) ⇒ Monitoring
constructor
A new instance of Monitoring.
- #schedule(worker) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #wait ⇒ Object
Methods included from Sleep
Constructor Details
#initialize(master) ⇒ Monitoring
Returns a new instance of Monitoring.
11 12 13 14 15 16 |
# File 'lib/delayed/master/monitoring.rb', line 11 def initialize(master) @master = master @config = master.config @callbacks = master.callbacks @threads = SafeArray.new end |
Instance Method Details
#schedule(worker) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/delayed/master/monitoring.rb', line 30 def schedule(worker) @threads << Thread.new do wait_pid(worker) @threads.delete(Thread.current) end end |
#shutdown ⇒ Object
41 42 43 |
# File 'lib/delayed/master/monitoring.rb', line 41 def shutdown @threads.each(&:kill) end |
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/delayed/master/monitoring.rb', line 18 def start @threads << Thread.new do loop_with_sleep @config.monitor_interval do |i| if @master.stop? break elsif i == 0 @callbacks.call(:monitor, @master) {} end end end end |
#wait ⇒ Object
37 38 39 |
# File 'lib/delayed/master/monitoring.rb', line 37 def wait @threads.each(&:join) end |