Class: Angael::Manager
- Inherits:
-
Object
- Object
- Angael::Manager
- Includes:
- ProcessHelper
- Defined in:
- lib/angael/manager.rb
Overview
A Manager has a number of of worker objects. Starting the Manager simply calls #start! on each worker, then it goes into an infinite loop, waiting for SIGINT or SIGTERM. When either of those is received, the manager will call #stop_with_wait on each Worker.
Constant Summary collapse
- LOOP_SLEEP_SECONDS =
1
Instance Attribute Summary collapse
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(worker_class, worker_count = 1, worker_args = [], opts = {}) ⇒ Manager
constructor
Creates a new manager.
-
#start! ⇒ Object
Starts workers by calling Worker#start! Loops forever waiting for SIGINT or SIGTERM, at which time it calls Worker#stop_with_wait on each worker.
Methods included from ProcessHelper
Constructor Details
#initialize(worker_class, worker_count = 1, worker_args = [], opts = {}) ⇒ Manager
Creates a new manager.
29 30 31 32 33 34 35 36 |
# File 'lib/angael/manager.rb', line 29 def initialize(worker_class, worker_count=1, worker_args=[], opts={}) @workers = [] worker_count.times { workers << worker_class.new(*worker_args) } @restart_after = opts[:restart_after] # TODO: Add a spec for this raise ArgumentError, ':restart_after must be either an Integer greater than zero or nil' if @restart_after && (@restart_after.to_i != @restart_after || @restart_after == 0) @logger = opts[:logger] end |
Instance Attribute Details
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
11 12 13 |
# File 'lib/angael/manager.rb', line 11 def workers @workers end |
Instance Method Details
#start! ⇒ Object
Starts workers by calling Worker#start! Loops forever waiting for SIGINT or SIGTERM, at which time it calls Worker#stop_with_wait on each worker.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/angael/manager.rb', line 41 def start! workers.each { |w| w.start! } trap("CHLD") do debug("SIGCHLD Received") @sigchld = true end trap("INT") do info("SIGINT Received") @interrupted = true end trap("TERM") do info("SIGTERM Received") @interrupted = true end if @restart_after loop do interrupted_handler sigchld_handler restart_worker_if_needed flush_logger sleep LOOP_SLEEP_SECONDS end else loop do interrupted_handler sigchld_handler flush_logger sleep LOOP_SLEEP_SECONDS end end end |