Class: RFlow::ChildProcess
- Inherits:
-
Object
- Object
- RFlow::ChildProcess
- Defined in:
- lib/rflow/child_process.rb
Overview
Encapsulates a child process being managed by RFlow.
Direct Known Subclasses
Constant Summary collapse
- SIGINFO =
Symbolic constant for SIGINFO as this is only defined on BSD and not in Ruby.
29
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the child process.
-
#pid ⇒ Fixnum
readonly
The PID of the child process.
Instance Method Summary collapse
-
#initialize(name, role = name) ⇒ ChildProcess
constructor
A new instance of ChildProcess.
-
#shutdown!(signal) ⇒ void
Called when the child process needs to be shut down, before it dies.
-
#spawn! ⇒ void
Launch another process to execute the child.
Constructor Details
#initialize(name, role = name) ⇒ ChildProcess
Returns a new instance of ChildProcess.
18 19 20 21 |
# File 'lib/rflow/child_process.rb', line 18 def initialize(name, role = name) @name = name @role = role end |
Instance Attribute Details
#name ⇒ String (readonly)
The name of the child process.
11 12 13 |
# File 'lib/rflow/child_process.rb', line 11 def name @name end |
#pid ⇒ Fixnum (readonly)
The PID of the child process.
8 9 10 |
# File 'lib/rflow/child_process.rb', line 8 def pid @pid end |
Instance Method Details
#shutdown!(signal) ⇒ void
This method returns an undefined value.
Called when the child process needs to be shut down, before it dies. Clears signal handlers.
65 66 67 68 |
# File 'lib/rflow/child_process.rb', line 65 def shutdown!(signal) RFlow.logger.info "Shutting down due to #{signal}" unhandle_signals end |
#spawn! ⇒ void
This method returns an undefined value.
Launch another process to execute the child. The parent process retains the original worker object (with pid and IPC pipe) to allow for process management. Parent will return once the child starts; child will update its process name, detach from the process group, set up signal handlers, and execute #run_child_process; when that returns, it will exit with return code 0.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rflow/child_process.rb', line 31 def spawn! establish_child_pipe drop_database_connections @pid = fork if @pid return_after_child_starts else run_child_process end end |