Class: Nonnative::Port
- Inherits:
-
Object
- Object
- Nonnative::Port
- Defined in:
- lib/nonnative/port.rb
Overview
Performs TCP port readiness/shutdown checks for a configured runner.
Nonnative uses this to decide whether a process/server port is ready after start, and whether it
has shut down after stop. The checks repeatedly attempt to open a TCP connection to process.host
and the configured port until either:
- the expected condition is met, or
- the configured timeout elapses (in which case the method returns
false)
The process argument is a runner configuration object (e.g. ConfigurationProcess
or ConfigurationServer) that responds to host and timeout.
Instance Method Summary collapse
-
#closed? ⇒ Boolean
Returns whether the configured host/port becomes non-connectable before the timeout elapses.
-
#endpoint ⇒ String
Returns a human-readable endpoint for lifecycle diagnostics.
-
#initialize(process, port = process.port) ⇒ Port
constructor
A new instance of Port.
-
#open? ⇒ Boolean
Returns whether the configured host/port becomes connectable before the timeout elapses.
Constructor Details
Instance Method Details
#closed? ⇒ Boolean
Returns whether the configured host/port becomes non-connectable before the timeout elapses.
This method treats a successful connection as “not closed yet” and keeps retrying until it
observes connection failure (returns true) or the timeout elapses (returns false).
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nonnative/port.rb', line 50 def closed? Nonnative.logger.info "checking if port '#{port}' is closed on host '#{process.host}'" timeout.perform do open_socket raise Nonnative::Error rescue Nonnative::Error sleep_interval retry rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET true end end |
#endpoint ⇒ String
Returns a human-readable endpoint for lifecycle diagnostics.
67 68 69 |
# File 'lib/nonnative/port.rb', line 67 def endpoint "#{process.host}:#{port}" end |
#open? ⇒ Boolean
Returns whether the configured host/port becomes connectable before the timeout elapses.
This method retries on common connection errors until either a connection succeeds
(returns true) or the timeout elapses (returns false).
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nonnative/port.rb', line 32 def open? Nonnative.logger.info "checking if port '#{port}' is open on host '#{process.host}'" timeout.perform do open_socket true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH sleep_interval retry end end |