Class: Rubish::UnixExecutable::UnixJob
- Defined in:
- lib/rubish/unix_executable.rb
Defined Under Namespace
Classes: BadExit
Instance Attribute Summary collapse
-
#bads ⇒ Object
readonly
Returns the value of attribute bads.
-
#goods ⇒ Object
readonly
Returns the value of attribute goods.
-
#pids ⇒ Object
readonly
Returns the value of attribute pids.
Attributes inherited from Job
Instance Method Summary collapse
-
#initialize(exe) ⇒ UnixJob
constructor
A new instance of UnixJob.
- #stop(sig = "TERM") ⇒ Object
- #stop! ⇒ Object
- #wait ⇒ Object
Methods inherited from Job
Constructor Details
#initialize(exe) ⇒ UnixJob
Returns a new instance of UnixJob.
16 17 18 19 20 21 22 23 24 |
# File 'lib/rubish/unix_executable.rb', line 16 def initialize(exe) # prepare_io returns an instance of ExeIO @ios = EIO.ios([exe.i || Rubish::Context.current.i,"r"], [exe.o || Rubish::Context.current.o,"w"], [exe.err || Rubish::Context.current.err,"w"]) i,o,err = @ios @pids = exe.exec_with(i.io,o.io,err.io) __start end |
Instance Attribute Details
#bads ⇒ Object (readonly)
Returns the value of attribute bads.
7 8 9 |
# File 'lib/rubish/unix_executable.rb', line 7 def bads @bads end |
#goods ⇒ Object (readonly)
Returns the value of attribute goods.
6 7 8 |
# File 'lib/rubish/unix_executable.rb', line 6 def goods @goods end |
#pids ⇒ Object (readonly)
Returns the value of attribute pids.
5 6 7 |
# File 'lib/rubish/unix_executable.rb', line 5 def pids @pids end |
Instance Method Details
#stop(sig = "TERM") ⇒ Object
48 49 50 51 52 53 |
# File 'lib/rubish/unix_executable.rb', line 48 def stop(sig="TERM") self.pids.each do |pid| Process.kill(sig,pid) end self.wait end |
#stop! ⇒ Object
55 56 57 |
# File 'lib/rubish/unix_executable.rb', line 55 def stop! self.stop("KILL") end |
#wait ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubish/unix_executable.rb', line 26 def wait raise Rubish::Error.new("already waited") if self.done? begin exits = self.pids.map do |pid| Process.wait(pid) $? end @ios.each do |io| io.close end @goods, @bads = exits.partition { |status| status.exitstatus == 0} @result = goods # set result to processes that exit properly if !bads.empty? raise Rubish::Job::Failure.new(self,BadExit.new(bads)) else return self.result end ensure __finish end end |