Class: QPush::Server::Manager

Inherits:
Object
  • Object
show all
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.



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

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

Instance Attribute Details

#configsObject

Returns the value of attribute configs.



7
8
9
# File 'lib/qpush/server/manager.rb', line 7

def configs
  @configs
end

#forksObject (readonly)

Returns the value of attribute forks.



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

def forks
  @forks
end

Instance Method Details

#shutdownObject

Shutsdown our Worker processes.



30
31
32
33
34
35
36
# File 'lib/qpush/server/manager.rb', line 30

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.



21
22
23
24
25
26
# File 'lib/qpush/server/manager.rb', line 21

def start
  start_messages
  flush_spaces
  create_workers
  Process.wait
end