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.



47
48
49
50
51
# File 'lib/async/container/process.rb', line 47

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.



36
37
38
39
40
41
42
43
44
45
# File 'lib/async/container/process.rb', line 36

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.



69
70
71
72
73
74
75
76
77
78
# File 'lib/async/container/process.rb', line 69

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.



63
64
65
# File 'lib/async/container/process.rb', line 63

def name
	@name
end

#name=(value) ⇒ Object

Set the process title to the specified value.



55
56
57
58
59
# File 'lib/async/container/process.rb', line 55

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