Class: Vedeu::Subprocess
- Inherits:
-
Object
- Object
- Vedeu::Subprocess
- Defined in:
- lib/vedeu/distributed/subprocess.rb
Overview
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
private
Returns the value of attribute application.
-
#pid ⇒ Object
private
Returns the value of attribute pid.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ String private
- #execute! ⇒ Array
- #file_close ⇒ NilClass private
- #file_open ⇒ File (also: #file) private
-
#file_path ⇒ Object
private
return [String].
-
#file_unlink ⇒ Fixnum
private
The number of files removed; 1.
-
#file_write ⇒ Fixnum
private
The number of bytes written.
- #initialize(application) ⇒ Vedeu::Subprocess constructor
-
#kill ⇒ void
Sends the KILL signal to the process.
-
#timestamp ⇒ Object
private
return [Fixnum].
Constructor Details
#initialize(application) ⇒ Vedeu::Subprocess
18 19 20 21 |
# File 'lib/vedeu/distributed/subprocess.rb', line 18 def initialize(application) @application = application @pid = nil end |
Instance Attribute Details
#application ⇒ Object (readonly, private)
Returns the value of attribute application.
47 48 49 |
# File 'lib/vedeu/distributed/subprocess.rb', line 47 def application @application end |
#pid ⇒ Object (private)
Returns the value of attribute pid.
48 49 50 |
# File 'lib/vedeu/distributed/subprocess.rb', line 48 def pid @pid end |
Class Method Details
.execute!(application) ⇒ Array
12 13 14 |
# File 'lib/vedeu/distributed/subprocess.rb', line 12 def self.execute!(application) new(application).execute! end |
Instance Method Details
#command ⇒ String (private)
51 52 53 |
# File 'lib/vedeu/distributed/subprocess.rb', line 51 def command "ruby #{file_path}" end |
#execute! ⇒ Array
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vedeu/distributed/subprocess.rb', line 24 def execute! file_open && file_write && file_close @pid = fork do exec(file_path) end Process.detach(@pid) self end |
#file_close ⇒ NilClass (private)
61 62 63 |
# File 'lib/vedeu/distributed/subprocess.rb', line 61 def file_close file.close end |
#file_open ⇒ File (private) Also known as: file
76 77 78 |
# File 'lib/vedeu/distributed/subprocess.rb', line 76 def file_open @file ||= File.new("/tmp/foo_#{timestamp}", "w", 0755) end |
#file_path ⇒ Object (private)
return [String]
71 72 73 |
# File 'lib/vedeu/distributed/subprocess.rb', line 71 def file_path file.path end |
#file_unlink ⇒ Fixnum (private)
Returns The number of files removed; 1.
66 67 68 |
# File 'lib/vedeu/distributed/subprocess.rb', line 66 def file_unlink File.unlink("/tmp/foo_#{timestamp}") end |
#file_write ⇒ Fixnum (private)
Returns The number of bytes written.
56 57 58 |
# File 'lib/vedeu/distributed/subprocess.rb', line 56 def file_write file.write(application) end |
#kill ⇒ void
This method returns an undefined value.
Sends the KILL signal to the process.
39 40 41 42 43 |
# File 'lib/vedeu/distributed/subprocess.rb', line 39 def kill Process.kill('KILL', pid) file_unlink end |
#timestamp ⇒ Object (private)
return [Fixnum]
82 83 84 |
# File 'lib/vedeu/distributed/subprocess.rb', line 82 def ||= Time.now.to_i end |