class ActiveHook::Server::Manager
The Manager
controls our Worker
processes. We use it to instruct each of them to start and shutdown.
Attributes
forks[R]
options[RW]
workers[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/activehook/server/manager.rb, line 10 def initialize(options = {}) options.each { |key, value| send("#{key}=", value) } @master = Process.pid at_exit { shutdown } end
Public Instance Methods
shutdown()
click to toggle source
Shutsdown our Worker
processes.
# File lib/activehook/server/manager.rb, line 29 def shutdown @forks.each { |w| Process.kill('SIGINT', w[:pid].to_i) } Process.kill('SIGINT', @master) end
start()
click to toggle source
Private Instance Methods
create_workers()
click to toggle source
Create the specified number of workers and starts them
# File lib/activehook/server/manager.rb, line 38 def create_workers @forks = [] @workers.times do |id| pid = fork { Worker.new(@options.merge(id: id)).start } @forks << { id: id, pid: pid } end end
start_messages()
click to toggle source
Information about the start process
# File lib/activehook/server/manager.rb, line 48 def start_messages ActiveHook.log.info("* Workers: #{@workers}") ActiveHook.log.info("* Threads: #{@options[:queue_threads]} queue, #{@options[:retry_threads]} retry") end
validate!()
click to toggle source
Validates our data before starting our Workers. Also instantiates our connection pool by pinging Redis.
# File lib/activehook/server/manager.rb, line 56 def validate! raise Errors::Server, 'Cound not connect to Redis.' unless ActiveHook.redis.with { |c| c.ping && c.quit } raise Errors::Server, 'Workers must be an Integer.' unless @workers.is_a?(Integer) raise Errors::Server, 'Options must be a Hash.' unless @options.is_a?(Hash) end