Class: Vedeu::Subprocess

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/distributed/subprocess.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ Vedeu::Subprocess

Returns a new instance of Vedeu::Subprocess.



16
17
18
19
# File 'lib/vedeu/distributed/subprocess.rb', line 16

def initialize(application)
  @application = application
  @pid         = nil
end

Instance Attribute Details

#applicationVedeu::TestApplication (readonly, protected)



49
50
51
# File 'lib/vedeu/distributed/subprocess.rb', line 49

def application
  @application
end

#pidFixnum (protected)



53
54
55
# File 'lib/vedeu/distributed/subprocess.rb', line 53

def pid
  @pid
end

Class Method Details

.execute!(application) ⇒ Object



8
9
10
# File 'lib/vedeu/distributed/subprocess.rb', line 8

def self.execute!(application)
  new(application).execute!
end

Instance Method Details

#commandString (private)



58
59
60
# File 'lib/vedeu/distributed/subprocess.rb', line 58

def command
  "ruby #{file_path}"
end

#execute!Array

:nocov:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vedeu/distributed/subprocess.rb', line 23

def execute!
  file_open && file_write && file_close

  @pid = fork do
    exec(file_path)
  end

  Process.detach(@pid)

  self
end

#file_closeNilClass (private)



68
69
70
# File 'lib/vedeu/distributed/subprocess.rb', line 68

def file_close
  file.close
end

#file_openFile (private) Also known as: file



83
84
85
# File 'lib/vedeu/distributed/subprocess.rb', line 83

def file_open
  @file ||= File.new("/tmp/foo_#{timestamp}", 'w', 0755)
end

#file_pathObject (private)

return [String]



78
79
80
# File 'lib/vedeu/distributed/subprocess.rb', line 78

def file_path
  file.path
end


73
74
75
# File 'lib/vedeu/distributed/subprocess.rb', line 73

def file_unlink
  File.unlink("/tmp/foo_#{timestamp}")
end

#file_writeFixnum (private)



63
64
65
# File 'lib/vedeu/distributed/subprocess.rb', line 63

def file_write
  file.write(application)
end

#killvoid

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

#timestampObject (private)

return [Fixnum]



89
90
91
# File 'lib/vedeu/distributed/subprocess.rb', line 89

def timestamp
  @timestamp ||= Time.now.to_i
end