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.

API:

  • private

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:

API:

  • private



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.

API:

  • private



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:

API:

  • private



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:

API:

  • private



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:

API:

  • private



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:

API:

  • private



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:

API:

  • private



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:

API:

  • private



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:

API:

  • private



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]

API:

  • private



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:

  • The number of files removed; 1.

API:

  • private



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:

  • The number of bytes written.

API:

  • private



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.

API:

  • private



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]

API:

  • private



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

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