Class: Vedeu::Distributed::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::Distributed::Subprocess

Returns a new instance of Vedeu::Distributed::Subprocess.

Parameters:



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

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

Instance Attribute Details

#applicationVedeu::TestApplication (readonly, protected)



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

def application
  @application
end

#pidFixnum (readonly, protected)

Returns:

  • (Fixnum)


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

def pid
  @pid
end

Class Method Details

.execute!(application) ⇒ Object

Parameters:



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

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

Instance Method Details

#commandString (private)

Returns:

  • (String)


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

def command
  "ruby #{file_path}".freeze
end

#execute!Array

:nocov:

Returns:

  • (Array)


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vedeu/distributed/subprocess.rb', line 26

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)


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

def file_close
  file.close
end

#file_nameString (private)

Returns:

  • (String)


92
93
94
# File 'lib/vedeu/distributed/subprocess.rb', line 92

def file_name
  "/tmp/foo_#{timestamp}".freeze
end

#file_openFile (private) Also known as: file

Returns:

  • (File)


86
87
88
# File 'lib/vedeu/distributed/subprocess.rb', line 86

def file_open
  @file ||= File.new(file_name, 'w', 0755)
end

#file_pathObject (private)

return [String]



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

def file_path
  file.path
end

Returns The number of files removed; 1.

Returns:

  • (Fixnum)

    The number of files removed; 1.



76
77
78
# File 'lib/vedeu/distributed/subprocess.rb', line 76

def file_unlink
  File.unlink(file_name)
end

#file_writeFixnum (private)

Returns The number of bytes written.

Returns:

  • (Fixnum)

    The number of bytes written.



66
67
68
# File 'lib/vedeu/distributed/subprocess.rb', line 66

def file_write
  file.write(application)
end

#killvoid

This method returns an undefined value.

Sends the KILL signal to the process.



42
43
44
45
46
# File 'lib/vedeu/distributed/subprocess.rb', line 42

def kill
  Process.kill('KILL', pid)

  file_unlink
end

#timestampObject (private)

return [Fixnum]



97
98
99
# File 'lib/vedeu/distributed/subprocess.rb', line 97

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