Class: QPush::Server::Manager

Inherits:
Object
  • Object
show all
Includes:
ObjectValidator::Validate
Defined in:
lib/qpush/server/manager.rb

Overview

The Manager controls our Worker processes. We use it to instruct each of them to start and shutdown.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configs) ⇒ Manager

Returns a new instance of Manager.



12
13
14
15
16
17
# File 'lib/qpush/server/manager.rb', line 12

def initialize(configs)
  @configs = configs
  @master = Process.pid
  @forks = []
  at_exit { shutdown }
end

Instance Attribute Details

#configsObject

Returns the value of attribute configs.



9
10
11
# File 'lib/qpush/server/manager.rb', line 9

def configs
  @configs
end

#forksObject (readonly)

Returns the value of attribute forks.



10
11
12
# File 'lib/qpush/server/manager.rb', line 10

def forks
  @forks
end

Instance Method Details

#shutdownObject

Shutsdown our Worker processes.



33
34
35
36
37
38
39
# File 'lib/qpush/server/manager.rb', line 33

def shutdown
  unless @forks.empty?
    @forks.each { |w| Process.kill('QUIT', w[:pid].to_i) }
  end
  Process.waitall
  Process.kill('SIGTERM', @master)
end

#startObject

Instantiates new Worker objects, setting them with our options. We follow up by booting each of our Workers. Our Manager is then put to sleep so that our Workers can do their thing.



23
24
25
26
27
28
29
# File 'lib/qpush/server/manager.rb', line 23

def start
  validate!
  start_messages
  flush_spaces
  create_workers
  Process.wait
end