Skip to content

Commit

Permalink
better async intermediate output for polly test
Browse files Browse the repository at this point in the history
  • Loading branch information
diclophis committed Apr 10, 2024
1 parent 6eb2273 commit c6a4855
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions Pollyfile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
{"run"=>{"name"=>"config","command"=>"bundle config set --local path vendor/bundle"}},
{"run"=>{"name"=>"bundler","command"=>"bundle install"}},
{"run"=>{"name"=>"rspec","command"=>"bundle exec rspec"}},
{"run"=>{"name"=>"demo","command"=>"polly help"}},
#{"run"=>{"name"=>"build","command"=>"pwd && ls -l && buildctl --timeout 120 --addr tcp://polly-buildkitd:1234 --tlsservername polly-buildkitd --tlscacert /certs/client/ca.pem --tlscert /certs/client/cert.pem --tlskey /certs/client/key.pem build --frontend dockerfile.v0 --local context=. --local dockerfile=."}}
],{},"/home/app/polly"
)
Expand Down
9 changes: 6 additions & 3 deletions bin/polly
Original file line number Diff line number Diff line change
Expand Up @@ -1681,13 +1681,16 @@ HEREDOC

#puts kube_exec_cmd.inspect #join(" ")

o,e,s = exe.execute_simple(:output, kube_exec_cmd, {})
s = exe.execute_simple(:async_wait_status, kube_exec_cmd, {}) #{:out => $stdout, :err => $stderr})

if s
puts o
#puts o
puts "OKOK"
else
puts e
#puts e
#fail
puts "fail"
fail
end
end
end
Expand Down
42 changes: 42 additions & 0 deletions lib/polly/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,48 @@ def execute_simple(mode, cmd, options)
o, e, s = Open3.capture3(*cmd, options)
return exit_proc.call(o, e, s, false)

when :async_wait_status
#o, e, s = Open3.capture3(*cmd, options)
#puts options.inspect
$stdout.sync = true
$stderr.sync = true

i, o, e, s = Open3.popen3(*cmd, options)

read_io = Proc.new {
chunk = 65432
begin
stdout = o.read_nonblock(chunk)
$stdout.write(stdout)
rescue IO::EAGAINWaitReadable, Errno::EIO, Errno::EAGAIN, Errno::EINTR => err
#_r, _w, _e = IO.select(process_fds, nil, process_fds, 0.5)
sleep 0.1
rescue EOFError => err
end

begin
stderr = e.read_nonblock(chunk)
$stderr.write(stderr)
rescue IO::EAGAINWaitReadable, Errno::EIO, Errno::EAGAIN, Errno::EINTR => err
#_r, _w, _e = IO.select(process_fds, nil, process_fds, 0.5)
sleep 0.1
rescue EOFError => err
end
}

while s.alive?
#$stdout.write(".")

read_io.call

s.join(0.1)
end

read_io.call

return s.value.success?
#return exit_proc.call(o, e, s, false)

when :async
stdin, stdout, stderr, wait_thr = Open3.popen3(*cmd, options)
return [stdin, stdout, stderr, wait_thr, exit_proc]
Expand Down

0 comments on commit c6a4855

Please sign in to comment.