Class: Harnex::TerminalWatcher
- Inherits:
-
Object
- Object
- Harnex::TerminalWatcher
- Defined in:
- lib/harnex/commands/watch.rb
Constant Summary collapse
- TIMEOUT_EXIT_CODE =
124
Instance Method Summary collapse
-
#initialize(id:, repo_path: Dir.pwd, until_state: "done", max_wait: nil, done_marker: nil, fail_marker: nil, stop_on_terminal: false, out: $stdout, err: $stderr) ⇒ TerminalWatcher
constructor
A new instance of TerminalWatcher.
- #run ⇒ Object
Constructor Details
#initialize(id:, repo_path: Dir.pwd, until_state: "done", max_wait: nil, done_marker: nil, fail_marker: nil, stop_on_terminal: false, out: $stdout, err: $stderr) ⇒ TerminalWatcher
Returns a new instance of TerminalWatcher.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/harnex/commands/watch.rb', line 216 def initialize( id:, repo_path: Dir.pwd, until_state: "done", max_wait: nil, done_marker: nil, fail_marker: nil, stop_on_terminal: false, out: $stdout, err: $stderr ) @id = Harnex.normalize_id(id) @repo_path = repo_path @until_state = until_state.to_s.strip.empty? ? "done" : until_state.to_s @max_wait = max_wait @done_marker = done_marker @fail_marker = fail_marker @stop_on_terminal = stop_on_terminal @out = out @err = err end |
Instance Method Details
#run ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/harnex/commands/watch.rb', line 238 def run raise "harnex watch: only --until done is supported" unless @until_state == "done" output, warnings, exit_code = capture_wait @err.write(warnings) unless warnings.empty? @out.write(output) unless output.empty? payload = parse_payload(output) outcome = classify(exit_code, payload) case outcome when :success write_marker(@done_marker, payload, outcome: outcome, exit_code: exit_code) when :failed write_marker(@fail_marker, payload, outcome: outcome, exit_code: exit_code) end stop_session if @stop_on_terminal && outcome != :timeout exit_code end |