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 readiness/shutdown via TCP port checks 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:



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

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



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

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)



32
33
34
35
36
37
38
39
40
41
# 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

  [pid, ::Process.waitpid2(pid, ::Process::WNOHANG).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).

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



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nonnative/process.rb', line 51

def stop
  stopped = true

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

  [pid, stopped]
ensure
  @memory = nil
end