Class: Nonnative::Pool

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

Overview

Orchestrates lifecycle for configured processes, servers and services.

A pool is created when start is called and is accessible via pool.

Lifecycle order is important:

  • On start: services, then servers, then processes; each tier completes readiness before the next
  • On stop: processes, then servers, then services

Readiness uses TCP port checks plus optional process HTTP/gRPC probes and optional service TCP checks. Shutdown uses configured TCP port checks.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Pool

Returns a new instance of Pool.

Parameters:



20
21
22
23
24
25
# File 'lib/nonnative/pool.rb', line 20

def initialize(configuration)
  @configuration = configuration
  @services = nil
  @servers = nil
  @processes = nil
end

Instance Method Details

#process_by_name(name) ⇒ Nonnative::Process

Finds a running process runner by configured name.

Parameters:

  • name (String)

Returns:

Raises:



84
85
86
# File 'lib/nonnative/pool.rb', line 84

def process_by_name(name)
  processes[runner_index(configuration.processes, name)].first
end

#resetvoid

This method returns an undefined value.

Resets service proxies in this pool.

This is used by the Cucumber @reset hook and is safe to call any time after the pool is created.



111
112
113
# File 'lib/nonnative/pool.rb', line 111

def reset
  services.each { |s| s.proxy.reset }
end

#rollbackArray<String>

Stops only runners that have already been instantiated in this pool.

This is used to rollback partial startup after a failed #start without constructing new runner wrappers as a side effect.

Returns:

  • (Array<String>)

    lifecycle and shutdown-check errors collected while rolling back



68
69
70
71
72
73
74
75
76
77
# File 'lib/nonnative/pool.rb', line 68

def rollback
  errors = []

  [existing_processes, existing_servers].each do |runners|
    errors.concat(run_lifecycle_checks(runners, :stop, :closed?, :rollback))
  end
  errors.concat(service_lifecycle(existing_services, :stop, :stop))

  errors
end

#server_by_name(name) ⇒ Nonnative::Server

Finds a running server runner by configured name.

Parameters:

  • name (String)

Returns:

Raises:



93
94
95
# File 'lib/nonnative/pool.rb', line 93

def server_by_name(name)
  servers[runner_index(configuration.servers, name)].first
end

#service_by_name(name) ⇒ Nonnative::Service

Finds a running service runner by configured name.

Parameters:

  • name (String)

Returns:

Raises:



102
103
104
# File 'lib/nonnative/pool.rb', line 102

def service_by_name(name)
  services[runner_index(configuration.services, name)]
end

#startArray<String>

Starts all configured runners and collects lifecycle and readiness errors.

Externally managed services are handled first and checked for opt-in readiness. Servers are then started and checked for readiness, followed by processes. Each readiness failure is described with the runner and, for a process that exited early, its termination detail.

Returns:

  • (Array<String>)

    lifecycle and readiness-check errors collected while starting



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

def start
  errors = []

  errors.concat(service_lifecycle(services, :start, :start))
  service_readiness_errors = check_service_readiness(services)
  errors.concat(service_readiness_errors)
  return errors if errors.any?

  [servers, processes].each { |runners| errors.concat(run_lifecycle_checks(runners, :start, :open?, :start)) }

  errors
end

#stopArray<String>

Stops all configured runners and collects lifecycle and shutdown errors.

Processes and servers are stopped first and checked for shutdown, including bounded server thread cleanup, then service proxies are stopped when configured.

Returns:

  • (Array<String>)

    lifecycle and shutdown-check errors collected while stopping



53
54
55
56
57
58
59
60
# File 'lib/nonnative/pool.rb', line 53

def stop
  errors = []

  [processes, servers].each { |runners| errors.concat(run_lifecycle_checks(runners, :stop, :closed?, :stop)) }
  errors.concat(service_lifecycle(services, :stop, :stop))

  errors
end