Class: Vedeu::Distributed::Subprocess Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Creates a subprocess of the DRb server.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ Vedeu::Distributed::Subprocess

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • application (void)


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

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

Instance Attribute Details

#applicationvoid (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



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

def application
  @application
end

#pidFixnum (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


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

def pid
  @pid
end

Class Method Details

.execute!(application) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • application (void)


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

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

Instance Method Details

#commandString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


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

def command
  "ruby #{file_path}"
end

#execute!Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nocov:

Returns:

  • (Array)


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

def execute!
  file_open && file_write && file_close

  @pid = fork { exec(file_path) }

  Process.detach(@pid)

  self
end

#file_closeNilClass (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (NilClass)


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

def file_close
  file.close
end

#file_nameString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


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

def file_name
  Dir.tmpdir + "/foo_#{timestamp}"
end

#file_openFile (private) Also known as: file

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (File)


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

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

#file_pathObject (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

return [String]



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

def file_path
  file.path
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The number of files removed; 1.

Returns:

  • (Fixnum)

    The number of files removed; 1.



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

def file_unlink
  File.unlink(file_name)
end

#file_writeFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The number of bytes written.

Returns:

  • (Fixnum)

    The number of bytes written.



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

def file_write
  file.write(application)
end

#killvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Sends the KILL signal to the process.



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

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

  file_unlink
end

#timestampObject (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

return [Fixnum]



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

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