class QPush::Server::Manager

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

Attributes

configs[RW]
forks[R]

Public Class Methods

new(configs) click to toggle source
# File lib/qpush/server/manager.rb, line 10
def initialize(configs)
  @configs = configs
  @master = Process.pid
  @forks = []
  at_exit { shutdown }
end

Public Instance Methods

shutdown() click to toggle source

Shutsdown our Worker processes.

# 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
start() click to toggle source

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.

# File lib/qpush/server/manager.rb, line 21
def start
  start_messages
  flush_spaces
  create_workers
  Process.wait
end

Private Instance Methods

create_workers() click to toggle source

Create the specified number of workers and starts them

# File lib/qpush/server/manager.rb, line 42
def create_workers
  @configs.each_with_index do |config, id|
    pid = fork { Worker.new(id, config).start }
    @forks << { id: id, pid: pid }
  end
end
flush_spaces() click to toggle source

Removes the list of namespaces used by our server from Redis. This prepares it for the new list that will be created by our workers.

# File lib/qpush/server/manager.rb, line 58
def flush_spaces
  Server.redis { |c| c.del("#{QPush::Base::KEY}:namespaces") }
end
start_messages() click to toggle source

Information about the start process

# File lib/qpush/server/manager.rb, line 51
def start_messages
  Server.log.info("* Worker count: #{@configs.count}")
end