Class: Nonnative::Process

Inherits:
Runner
  • Object
show all
Defined in:
lib/nonnative/process.rb

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 TCP readiness/shutdown checks plus optional HTTP/gRPC readiness probes orchestrated by Pool.

The underlying configuration is a ConfigurationProcess.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Runner

#name

Constructor Details

#initialize(service) ⇒ Process

Returns a new instance of Process.

Parameters:



18
19
20
21
22
# File 'lib/nonnative/process.rb', line 18

def initialize(service)
  super

  @timeout = Nonnative::Timeout.new(service.timeout)
end

Instance Attribute Details

#memoryGetProcessMem? (readonly)

Returns memory reader for the current process lifecycle.

Returns:

  • (GetProcessMem, nil)

    memory reader for the current process lifecycle



25
26
27
# File 'lib/nonnative/process.rb', line 25

def memory
  @memory
end

Instance Method Details

#startArray<(Integer, Boolean)>

Spawns the configured process if it is not already running.

Returns:

  • (Array<(Integer, Boolean)>)

    a tuple of:

    • the spawned process id (pid)
    • whether the process appears to still be running (non-blocking wait result)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nonnative/process.rb', line 33

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

#stopArray<(Integer, Boolean)>

Stops the process if it is running.

The process is signalled using the configured signal (defaults to INT when not set). If it does not exit before the configured timeout, it is killed and the returned success value is false; Nonnative.stop reports that outcome as a StopError.

Returns:

  • (Array<(Integer, Boolean)>)

    a tuple of:

    • the pid that was stopped (or nil if the process was never started)
    • whether the process exited before the configured timeout


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nonnative/process.rb', line 57

def stop
  stopped = true

  if process_exists?
    process_kill
    stopped = wait_stop != false
    force_stop unless stopped
  end

  [pid, stopped]
ensure
  @memory = nil
end

#terminationString?

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.

Returns:

  • (String, nil)

    termination detail (exit status or terminating signal), or nil



78
79
80
81
82
83
# File 'lib/nonnative/process.rb', line 78

def termination
  status = captured_status
  return if status.nil?

  terminated_description(status)
end