Class: Dash::Cli::Healthcheck::ProgressReporter
- Inherits:
-
Object
- Object
- Dash::Cli::Healthcheck::ProgressReporter
- Defined in:
- lib/dash/cli/healthcheck/progress_reporter.rb
Overview
Turns the server-side readiness wait's progress lines back into the beacon the client-side poll used to print. It is an SSHKit interaction handler, so it sees the wait's stderr as it streams — the operator gets the same once-a-second feedback they got when the laptop was the thing doing the polling, for one round trip instead of one per attempt. The cadence is fixed at a second because the host loop's is.
The stream is line-oriented but arrives in chunks (the SSH backend splits on packet boundaries, not newlines), so data is buffered and only whole lines are reported. Only stderr is buffered: the wait's stdout carries the final status, and stdout and stderr are separate SSH streams whose chunks can interleave — folding both into one buffer would let the status land in the middle of a half-arrived progress line and corrupt them both. Anything on stderr that is not a progress line (docker's own complaints) is ignored.
Constant Summary collapse
- LINE =
/\A#{Regexp.escape(Dash::Commands::Base::READINESS_PROGRESS_PREFIX)} (?<elapsed>\d+) (?<left>\d+)(?: |\z)/
Instance Method Summary collapse
-
#initialize ⇒ ProgressReporter
constructor
A new instance of ProgressReporter.
-
#on_data(_command, stream_name, data, _channel = nil) ⇒ Object
SSHKit's interaction-handler contract.
Constructor Details
#initialize ⇒ ProgressReporter
Returns a new instance of ProgressReporter.
16 17 18 19 |
# File 'lib/dash/cli/healthcheck/progress_reporter.rb', line 16 def initialize @buffer = +"" @mutex = Mutex.new end |
Instance Method Details
#on_data(_command, stream_name, data, _channel = nil) ⇒ Object
SSHKit's interaction-handler contract.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dash/cli/healthcheck/progress_reporter.rb', line 22 def on_data(_command, stream_name, data, _channel = nil) return unless stream_name == :stderr @mutex.synchronize do @buffer << data.to_s while (newline = @buffer.index("\n")) report @buffer.slice!(0..newline).chomp end end end |