何度も手でdigdag logを打つのは面倒
digdag logは時々「error: Attempted read on closed stream. (io)」エラーになる(0.9.4にて)
digdag UIはログの取りこぼしがある(0.9.4にて)
digdag_log.rb
require 'open3'
STDOUT.sync = true
attempt_id = ARGV[0]
log_line_no_max = 0
attempt_stdout = nil
loop do
# digdag attempt実行 (エラーなら即終了)
status = nil
attempt_stdout = []
Open3.popen3("digdag attempt " + attempt_id) do |stdin, stdout, stderr, wait_thr|
stdout.each do |line|
tmp = line.match(/ status: (.+)/)
status = tmp[1] unless tmp.nil?
attempt_stdout << line
end
unless wait_thr.value.success?
stdout.each do |line| puts line end
stderr.each do |line| STDERR.puts line end
abort
end
end
# digdag log実行 (正常終了するまで繰り返す)
loop do
log_line_no = 0
log_success = false
Open3.popen3("digdag log " + attempt_id) do |stdin, stdout, stderr, wait_thr|
stdout.each do |line|
log_line_no += 1
# 前回出力行以降を出力
if (log_line_no > log_line_no_max)
puts line
log_line_no_max = log_line_no
end
end
log_success = wait_thr.value.success?
end
if log_success
break
end
end
# attemptが終了しているか
if status == "error" || status == "success"
break
end
# 次の実行までスリープ
sleep 10
end
puts
puts "this attempt ended with following status"
puts
puts attempt_stdout
ruby digdag_log.rb 6