Class: Nonnative::Pool
- Inherits:
-
Object
- Object
- Nonnative::Pool
- 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 first, then servers/processes (in parallel port-check threads)
-
On stop: processes/servers first, then services
Readiness and shutdown are determined via TCP port checks (Nonnative::Port#open? / Nonnative::Port#closed?).
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Pool
constructor
A new instance of Pool.
-
#process_by_name(name) ⇒ Nonnative::Process
Finds a running process runner by configured name.
-
#reset ⇒ void
Resets proxies for all runners in this pool.
-
#rollback {|name, id, result| ... } ⇒ Array<String>
Stops only runners that have already been instantiated in this pool.
-
#server_by_name(name) ⇒ Nonnative::Server
Finds a running server runner by configured name.
-
#service_by_name(name) ⇒ Nonnative::Service
Finds a running service runner by configured name.
-
#start {|name, values, result| ... } ⇒ Array<String>
Starts all configured runners and yields results for each process/server.
-
#stop {|name, id, result| ... } ⇒ Array<String>
Stops all configured runners and yields results for each process/server.
Constructor Details
#initialize(configuration) ⇒ Pool
Returns a new instance of Pool.
19 20 21 22 23 24 |
# File 'lib/nonnative/pool.rb', line 19 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.
83 84 85 |
# File 'lib/nonnative/pool.rb', line 83 def process_by_name(name) processes[runner_index(configuration.processes, name)].first end |
#reset ⇒ void
This method returns an undefined value.
Resets proxies for all runners in this pool.
This is used by the Cucumber ‘@reset` hook and is safe to call any time after the pool is created.
110 111 112 113 114 |
# File 'lib/nonnative/pool.rb', line 110 def reset services.each { |s| s.proxy.reset } servers.each { |s| s.first.proxy.reset } processes.each { |p| p.first.proxy.reset } end |
#rollback {|name, id, result| ... } ⇒ Array<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.
69 70 71 72 73 74 75 76 |
# File 'lib/nonnative/pool.rb', line 69 def rollback(&) errors = [] [existing_processes, existing_servers].each { |t| errors.concat(process(t, :stop, :closed?, :stop, &)) } errors.concat(service_lifecycle(existing_services, :stop, :stop)) errors end |
#server_by_name(name) ⇒ Nonnative::Server
Finds a running server runner by configured name.
92 93 94 |
# File 'lib/nonnative/pool.rb', line 92 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.
101 102 103 |
# File 'lib/nonnative/pool.rb', line 101 def service_by_name(name) services[runner_index(configuration.services, name)] end |
#start {|name, values, result| ... } ⇒ Array<String>
Starts all configured runners and yields results for each process/server.
Services are started first (proxy-only), then servers and processes are started and checked for readiness.
34 35 36 37 38 39 40 41 |
# File 'lib/nonnative/pool.rb', line 34 def start(&) errors = [] errors.concat(service_lifecycle(services, :start, :start)) [servers, processes].each { |t| errors.concat(process(t, :start, :open?, :start, &)) } errors end |
#stop {|name, id, result| ... } ⇒ Array<String>
Stops all configured runners and yields results for each process/server.
Processes and servers are stopped first and checked for shutdown, then services are stopped (proxy-only).
51 52 53 54 55 56 57 58 |
# File 'lib/nonnative/pool.rb', line 51 def stop(&) errors = [] [processes, servers].each { |t| errors.concat(process(t, :stop, :closed?, :stop, &)) } errors.concat(service_lifecycle(services, :stop, :stop)) errors end |