Class: Vedeu::Subprocess

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

Overview

Examples:

Vedeu::TestApplication.build

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ Vedeu::Subprocess

Parameters:



18
19
20
21
# File 'lib/vedeu/distributed/subprocess.rb', line 18

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

Instance Attribute Details

#applicationObject (readonly, private)

Returns the value of attribute application.



47
48
49
# File 'lib/vedeu/distributed/subprocess.rb', line 47

def application
  @application
end

#pidObject (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

Parameters:

Returns:

  • (Array)


12
13
14
# File 'lib/vedeu/distributed/subprocess.rb', line 12

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

Instance Method Details

#commandString (private)

Returns:

  • (String)


51
52
53
# File 'lib/vedeu/distributed/subprocess.rb', line 51

def command
  "ruby #{file_path}"
end

#execute!Array

Returns:

  • (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_closeNilClass (private)

Returns:

  • (NilClass)


61
62
63
# File 'lib/vedeu/distributed/subprocess.rb', line 61

def file_close
  file.close
end

#file_openFile (private) Also known as: file

Returns:

  • (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_pathObject (private)

return [String]



71
72
73
# File 'lib/vedeu/distributed/subprocess.rb', line 71

def file_path
  file.path
end

Returns The number of files removed; 1.

Returns:

  • (Fixnum)

    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_writeFixnum (private)

Returns The number of bytes written.

Returns:

  • (Fixnum)

    The number of bytes written.



56
57
58
# File 'lib/vedeu/distributed/subprocess.rb', line 56

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]



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

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