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:

  • starts the configured proxy (if any),

  • 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

Attributes inherited from Runner

#proxy

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 Method Details

#memoryGetProcessMem?

Returns a memoized memory reader for the spawned process.

This is primarily used by acceptance tests to assert memory usage.

Returns:

  • (GetProcessMem, nil)

    a memory reader for the pid, or nil if not started



60
61
62
63
64
# File 'lib/nonnative/process.rb', line 60

def memory
  return if pid.nil?

  @memory ||= GetProcessMem.new(pid)
end

#startArray<(Integer, Boolean)>

Starts the proxy (if any) and 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)



30
31
32
33
34
35
36
37
38
# File 'lib/nonnative/process.rb', line 30

def start
  unless process_exists?
    proxy.start
    @pid = process_spawn
    wait_start
  end

  [pid, ::Process.waitpid2(pid, ::Process::WNOHANG).nil?]
end

#stopInteger?

Stops the process (if running) and stops the proxy (if any).

The process is signalled using the configured signal (defaults to INT when not set).

Returns:

  • (Integer, nil)

    the pid that was stopped (or nil if the process was never started)



45
46
47
48
49
50
51
52
53
# File 'lib/nonnative/process.rb', line 45

def stop
  if process_exists?
    process_kill
    proxy.stop
    wait_stop
  end

  pid
end