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
Restart the 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 9 |
# File 'lib/xpool/process.rb', line 6 def initialize reset @id = spawn end |
Instance Method Details
#alive? ⇒ Boolean
Returns true when the process is still running.
94 95 96 |
# File 'lib/xpool/process.rb', line 94 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.
114 115 116 117 |
# File 'lib/xpool/process.rb', line 114 def backtrace synchronize! @states[:backtrace] end |
#busy? ⇒ Boolean
Returns true when the process is executing a unit of work.
68 69 70 71 |
# File 'lib/xpool/process.rb', line 68 def busy? synchronize! @states[:busy] end |
#dead? ⇒ Boolean
Returns true when the process has shutdown.
102 103 104 105 |
# File 'lib/xpool/process.rb', line 102 def dead? synchronize! @states[:dead] end |
#failed? ⇒ Boolean
Returns true when the process has failed due to an unhandled exception.
85 86 87 88 |
# File 'lib/xpool/process.rb', line 85 def failed? synchronize! @states[:failed] end |
#frequency ⇒ Fixnum
Returns The number of times the process has been asked to schedule work.
37 38 39 |
# File 'lib/xpool/process.rb', line 37 def frequency @frequency end |
#idle? ⇒ Boolean
Returns true when the process is not executing a unit of work.
77 78 79 |
# File 'lib/xpool/process.rb', line 77 def idle? !busy? end |
#restart ⇒ Fixnum
Restart the process. The current process shuts down(gracefully) and a new process replaces it. If the current process has failed the new process will inherit its message queue.
127 128 129 130 131 |
# File 'lib/xpool/process.rb', line 127 def restart _shutdown 'SIGUSR1', false reset(false) @id = spawn end |
#schedule(unit, *args) ⇒ XPool::Process
Returns self
54 55 56 57 58 59 60 61 62 |
# File 'lib/xpool/process.rb', line 54 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.
20 21 22 |
# File 'lib/xpool/process.rb', line 20 def shutdown _shutdown 'SIGUSR1' unless @shutdown end |
#shutdown! ⇒ void
This method returns an undefined value.
A non-graceful shutdown through SIGKILL.
29 30 31 |
# File 'lib/xpool/process.rb', line 29 def shutdown! _shutdown 'SIGKILL' unless @shutdown end |