Class: Async::Container::Process::Instance

Inherits:
Notify::Pipe show all
Defined in:
lib/async/container/process.rb

Overview

Represents a running child process from the point of view of the child process.

Constant Summary

Constants inherited from Notify::Pipe

Notify::Pipe::NOTIFY_PIPE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Notify::Pipe

#before_spawn, open!, #send

Methods inherited from Notify::Client

#error!, #ready!, #reloading!, #restarting!, #status!, #stopping!

Constructor Details

#initialize(io) ⇒ Instance

Returns a new instance of Instance.



30
31
32
33
34
# File 'lib/async/container/process.rb', line 30

def initialize(io)
  super
  
  @name = nil
end

Class Method Details

.for(process) ⇒ Object

Wrap an instance around the Async::Container::Process instance from within the forked child.



19
20
21
22
23
24
25
26
27
28
# File 'lib/async/container/process.rb', line 19

def self.for(process)
  instance = self.new(process.out)
  
  # The child process won't be reading from the channel:
  process.close_read
  
  instance.name = process.name
  
  return instance
end

Instance Method Details

#exec(*arguments, ready: true, **options) ⇒ Object

Replace the current child process with a different one. Forwards arguments and options to Process.exec. This method replaces the child process with the new executable, thus this method never returns.



52
53
54
55
56
57
58
59
60
61
# File 'lib/async/container/process.rb', line 52

def exec(*arguments, ready: true, **options)
  if ready
    self.ready!(status: "(exec)") if ready
  else
    self.before_spawn(arguments, options)
  end
  
  # TODO prefer **options... but it doesn't support redirections on < 2.7
  ::Process.exec(*arguments, options)
end

#nameObject

The name of the process.



46
47
48
# File 'lib/async/container/process.rb', line 46

def name
  @name
end

#name=(value) ⇒ Object

Set the process title to the specified value.



38
39
40
41
42
# File 'lib/async/container/process.rb', line 38

def name= value
  if @name = value
    ::Process.setproctitle(@name)
  end
end