Class: XPool::Process
- Inherits:
-
Object
- Object
- XPool::Process
- Defined in:
- lib/xpool/process.rb
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Returns true when the process is still running.
-
#backtrace ⇒ Array<String>
If a process has failed (see #failed?) this method returns the backtrace of the exception that caused the process to fail.
-
#busy? ⇒ Boolean
Returns true when the process is executing a unit of work.
-
#dead? ⇒ Boolean
Returns true when the process has shutdown.
-
#failed? ⇒ Boolean
Returns true when the process has failed due to an unhandled exception.
-
#frequency ⇒ Fixnum
The number of times the process has been asked to schedule work.
-
#idle? ⇒ Boolean
Returns true when the process is not executing a unit of work.
-
#initialize ⇒ XPool::Process
constructor
Returns an instance of XPool::Process.
-
#restart ⇒ Fixnum
Returns the process ID of the new process.
-
#schedule(unit, *args) ⇒ XPool::Process
Returns self.
-
#shutdown ⇒ void
A graceful shutdown of the process.
-
#shutdown! ⇒ void
A non-graceful shutdown through SIGKILL.
Constructor Details
#initialize ⇒ XPool::Process
Returns an instance of XPool::Process
6 7 8 |
# File 'lib/xpool/process.rb', line 6 def initialize @id = spawn end |
Instance Method Details
#alive? ⇒ Boolean
Returns true when the process is still running.
93 94 95 |
# File 'lib/xpool/process.rb', line 93 def alive? !dead? end |
#backtrace ⇒ Array<String>
If a process has failed (see #failed?) this method returns the backtrace of the exception that caused the process to fail.
113 114 115 116 |
# File 'lib/xpool/process.rb', line 113 def backtrace synchronize! @states[:backtrace] end |
#busy? ⇒ Boolean
Returns true when the process is executing a unit of work.
67 68 69 70 |
# File 'lib/xpool/process.rb', line 67 def busy? synchronize! @states[:busy] end |
#dead? ⇒ Boolean
Returns true when the process has shutdown.
101 102 103 104 |
# File 'lib/xpool/process.rb', line 101 def dead? synchronize! @states[:dead] end |
#failed? ⇒ Boolean
Returns true when the process has failed due to an unhandled exception.
84 85 86 87 |
# File 'lib/xpool/process.rb', line 84 def failed? synchronize! @states[:failed] end |
#frequency ⇒ Fixnum
Returns The number of times the process has been asked to schedule work.
36 37 38 |
# File 'lib/xpool/process.rb', line 36 def frequency @frequency end |
#idle? ⇒ Boolean
Returns true when the process is not executing a unit of work.
76 77 78 |
# File 'lib/xpool/process.rb', line 76 def idle? !busy? end |
#restart ⇒ Fixnum
Returns the process ID of the new process.
122 123 124 125 |
# File 'lib/xpool/process.rb', line 122 def restart shutdown @id = spawn end |
#schedule(unit, *args) ⇒ XPool::Process
Returns self
53 54 55 56 57 58 59 60 61 |
# File 'lib/xpool/process.rb', line 53 def schedule(unit,*args) if dead? raise RuntimeError, "cannot schedule work on a dead process (with ID: #{@id})" end @frequency += 1 @channel.put unit: unit, args: args self end |
#shutdown ⇒ void
This method returns an undefined value.
A graceful shutdown of the process.
The signal 'SIGUSR1' is caught in the subprocess and exit is performed through Kernel#exit after the process has finished executing its work.
19 20 21 |
# File 'lib/xpool/process.rb', line 19 def shutdown _shutdown 'SIGUSR1' unless @shutdown end |
#shutdown! ⇒ void
This method returns an undefined value.
A non-graceful shutdown through SIGKILL.
28 29 30 |
# File 'lib/xpool/process.rb', line 28 def shutdown! _shutdown 'SIGKILL' unless @shutdown end |