Class: ActiveHook::Server::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/activehook/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(options = {}) ⇒ Manager

Returns a new instance of Manager.



10
11
12
13
14
# 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

Instance Attribute Details

#forksObject (readonly)

Returns the value of attribute forks.



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

def forks
  @forks
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#workersObject

Returns the value of attribute workers.



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

def workers
  @workers
end

Instance Method Details

#shutdownObject

Shutsdown our Worker processes.



29
30
31
32
# 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

#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.



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

def start
  validate!
  start_messages
  create_workers
  Process.wait
end