Class: Async::Container::Forked::Child::Instance
- Inherits:
-
Notify::Pipe
- Object
- Notify::Client
- Notify::Pipe
- Async::Container::Forked::Child::Instance
- Defined in:
- lib/async/container/forked.rb
Overview
Represents a running child process from the point of view of the child process.
Constant Summary
Constants inherited from Notify::Pipe
Class Method Summary collapse
-
.for(process) ⇒ Object
Wrap an instance around the Process instance from within the forked child.
Instance Method Summary collapse
-
#as_json ⇒ Object
Generate a hash representation of the process.
-
#exec(*arguments, ready: true, **options) ⇒ Object
Replace the current child process with a different one.
-
#initialize(io) ⇒ Instance
constructor
Initialize the child process instance.
- #name ⇒ Object
-
#name=(value) ⇒ Object
Set the process title to the specified value.
-
#to_json ⇒ Object
Generate a JSON representation of the process.
Methods inherited from Notify::Pipe
Methods inherited from Notify::Client
#error!, #ready!, #reloading!, #restarting!, #status!, #stopping!
Constructor Details
#initialize(io) ⇒ Instance
Initialize the child process instance.
41 42 43 44 45 |
# File 'lib/async/container/forked.rb', line 41 def initialize(io) super @name = nil end |
Class Method Details
.for(process) ⇒ Object
Wrap an instance around the Process instance from within the forked child.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/async/container/forked.rb', line 27 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
#as_json ⇒ Object
Generate a hash representation of the process.
50 51 52 53 54 55 |
# File 'lib/async/container/forked.rb', line 50 def as_json(...) { process_id: ::Process.pid, name: @name, } end |
#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.
85 86 87 88 89 90 91 92 93 |
# File 'lib/async/container/forked.rb', line 85 def exec(*arguments, ready: true, **) if ready self.ready!(status: "(exec)") else self.before_spawn(arguments, ) end ::Process.exec(*arguments, **) end |
#name ⇒ Object
75 76 77 |
# File 'lib/async/container/forked.rb', line 75 def name @name end |
#name=(value) ⇒ Object
Set the process title to the specified value.
67 68 69 70 71 72 |
# File 'lib/async/container/forked.rb', line 67 def name= value @name = value # This sets the process title to an empty string if the name is nil: ::Process.setproctitle(@name.to_s) end |
#to_json ⇒ Object
Generate a JSON representation of the process.
60 61 62 |
# File 'lib/async/container/forked.rb', line 60 def to_json(...) as_json.to_json(...) end |