Class: Nonnative::Process
Overview
Runtime runner that manages an OS-level child process.
A process runner:
- spawns a child process using the configured command and environment,
- waits briefly (via the runner
wait), and - participates in readiness/shutdown via TCP port checks orchestrated by Pool.
The underlying configuration is a ConfigurationProcess.
Instance Attribute Summary collapse
-
#memory ⇒ GetProcessMem?
readonly
Memory reader for the current process lifecycle.
Instance Method Summary collapse
-
#initialize(service) ⇒ Process
constructor
A new instance of Process.
-
#start ⇒ Array<(Integer, Boolean)>
Spawns the configured process if it is not already running.
-
#stop ⇒ Array<(Integer, Boolean)>
Stops the process if it is running.
-
#termination ⇒ String?
Describes how the process terminated when it exited before becoming ready.
Methods inherited from Runner
Constructor Details
Instance Attribute Details
#memory ⇒ GetProcessMem? (readonly)
Returns memory reader for the current process lifecycle.
24 25 26 |
# File 'lib/nonnative/process.rb', line 24 def memory @memory end |
Instance Method Details
#start ⇒ Array<(Integer, Boolean)>
Spawns the configured process if it is not already running.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nonnative/process.rb', line 32 def start unless process_exists? @pid = process_spawn # Keep memory reads bound to the child spawned for this lifecycle. @memory = GetProcessMem.new(pid) wait_start end # Retain the reaped status for this lifecycle so startup diagnostics can report it. status = ::Process.waitpid2(pid, ::Process::WNOHANG) @status = status&.last [pid, status.nil?] end |
#stop ⇒ Array<(Integer, Boolean)>
Stops the process if it is running.
The process is signalled using the configured signal (defaults to INT when not set).
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nonnative/process.rb', line 54 def stop stopped = true if process_exists? process_kill stopped = wait_stop != false force_stop unless stopped end [pid, stopped] ensure @memory = nil end |
#termination ⇒ String?
Describes how the process terminated when it exited before becoming ready.
Returns nil while the process is still running, so callers can distinguish an early exit
from a live process that merely missed its readiness window. The check is non-blocking and
reuses the status captured during #start when available.
75 76 77 78 79 80 |
# File 'lib/nonnative/process.rb', line 75 def termination status = captured_status return if status.nil? terminated_description(status) end |