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 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 `process.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`, `port`, and `timeout`.
Instance Method Summary collapse
-
#closed? ⇒ Boolean
Returns whether the configured host/port becomes non-connectable before the timeout elapses.
-
#initialize(process) ⇒ 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`).
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nonnative/port.rb', line 48 def closed? Nonnative.logger.info "checking if port '#{process.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 |
#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`).
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nonnative/port.rb', line 30 def open? Nonnative.logger.info "checking if port '#{process.port}' is open on host '#{process.host}'" timeout.perform do open_socket true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH sleep_interval retry end end |