Class: Invoker::Commander
- Inherits:
-
Object
- Object
- Invoker::Commander
- Extended by:
- Forwardable
- Defined in:
- lib/invoker/commander.rb
Instance Attribute Summary collapse
-
#event_manager ⇒ Object
Returns the value of attribute event_manager.
-
#process_manager ⇒ Object
Returns the value of attribute process_manager.
-
#reactor ⇒ Object
Returns the value of attribute reactor.
-
#runnables ⇒ Object
Returns the value of attribute runnables.
-
#thread_group ⇒ Object
Returns the value of attribute thread_group.
Instance Method Summary collapse
-
#initialize ⇒ Commander
constructor
A new instance of Commander.
- #on_next_tick(*args, &block) ⇒ Object
- #run_runnables ⇒ Object
-
#start_manager ⇒ Object
Start the invoker process supervisor.
Constructor Details
#initialize ⇒ Commander
Returns a new instance of Commander.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/invoker/commander.rb', line 19 def initialize @thread_group = ThreadGroup.new @runnable_mutex = Mutex.new @event_manager = Invoker::Event::Manager.new @runnables = [] @reactor = Invoker::Reactor.new @process_manager = Invoker::ProcessManager.new Thread.abort_on_exception = true end |
Instance Attribute Details
#event_manager ⇒ Object
Returns the value of attribute event_manager.
10 11 12 |
# File 'lib/invoker/commander.rb', line 10 def event_manager @event_manager end |
#process_manager ⇒ Object
Returns the value of attribute process_manager.
9 10 11 |
# File 'lib/invoker/commander.rb', line 9 def process_manager @process_manager end |
#reactor ⇒ Object
Returns the value of attribute reactor.
9 10 11 |
# File 'lib/invoker/commander.rb', line 9 def reactor @reactor end |
#runnables ⇒ Object
Returns the value of attribute runnables.
10 11 12 |
# File 'lib/invoker/commander.rb', line 10 def runnables @runnables end |
#thread_group ⇒ Object
Returns the value of attribute thread_group.
10 11 12 |
# File 'lib/invoker/commander.rb', line 10 def thread_group @thread_group end |
Instance Method Details
#on_next_tick(*args, &block) ⇒ Object
49 50 51 52 53 |
# File 'lib/invoker/commander.rb', line 49 def on_next_tick(*args, &block) @runnable_mutex.synchronize do @runnables << OpenStruct.new(:args => args, :block => block) end end |
#run_runnables ⇒ Object
55 56 57 58 59 60 |
# File 'lib/invoker/commander.rb', line 55 def run_runnables @runnables.each do |runnable| instance_exec(*runnable.args, &runnable.block) end @runnables = [] end |
#start_manager ⇒ Object
Start the invoker process supervisor. This method starts a unix server in separate thread that listens for incoming commands.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/invoker/commander.rb', line 33 def start_manager verify_process_configuration daemonize_app if Invoker.daemonize? install_interrupt_handler unix_server_thread = Thread.new { Invoker::IPC::Server.new } @thread_group.add(unix_server_thread) process_manager.run_power_server Invoker.config.autorunnable_processes.each do |process_info| process_manager.start_process(process_info) Logger.puts("Starting process - #{process_info.label} waiting for #{process_info.sleep_duration} seconds...") sleep(process_info.sleep_duration) end at_exit { process_manager.kill_workers } start_event_loop end |