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:



21
22
23
24
# File 'lib/vedeu/distributed/subprocess.rb', line 21

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

Instance Attribute Details

#applicationVedeu::TestApplication (readonly, protected)



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

def application
  @application
end

#pidFixnum (readonly, protected)

Returns:

  • (Fixnum)


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

def pid
  @pid
end

Class Method Details

.execute!(application) ⇒ Object

Parameters:



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

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

Instance Method Details

#commandString (private)

Returns:

  • (String)


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

def command
  "ruby #{file_path}"
end

#execute!Array

:nocov:

Returns:

  • (Array)


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

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)


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

def file_close
  file.close
end

#file_nameString (private)

Returns:

  • (String)


94
95
96
# File 'lib/vedeu/distributed/subprocess.rb', line 94

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

#file_openFile (private) Also known as: file

Returns:

  • (File)


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

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

#file_pathObject (private)

return [String]



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

def file_path
  file.path
end

Returns The number of files removed; 1.

Returns:

  • (Fixnum)

    The number of files removed; 1.



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

def file_unlink
  File.unlink(file_name)
end

#file_writeFixnum (private)

Returns The number of bytes written.

Returns:

  • (Fixnum)

    The number of bytes written.



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

def file_write
  file.write(application)
end

#killvoid

This method returns an undefined value.

Sends the KILL signal to the process.



44
45
46
47
48
# File 'lib/vedeu/distributed/subprocess.rb', line 44

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

  file_unlink
end

#timestampObject (private)

return [Fixnum]



99
100
101
# File 'lib/vedeu/distributed/subprocess.rb', line 99

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