class CodeBuildTail::Main
Public Class Methods
new(source)
click to toggle source
# File lib/code_build_tail/main.rb, line 10 def initialize(source) @source = source @logs = CodeBuildTail::Logs.new(Aws::CloudWatchLogs::Client.new, true, 100) end
Public Instance Methods
follow_build()
click to toggle source
# File lib/code_build_tail/main.rb, line 37 def follow_build @build.refresh if @build.missing? puts "No build found for id #{@build.build_id}" return 1 end loop do @logs.poll_and_show_logs(@build.logs.group_name, @build.logs.stream_name) unless @build.logs.nil? @build.refresh break unless @build.running? # Prevent us from getting rate limitted. sleep(sleep_time) end @logs.poll_and_show_logs(@build.logs.group_name, @build.logs.stream_name) unless @build.logs.nil? if @build.successful? 0 else 1 end end
read_build()
click to toggle source
# File lib/code_build_tail/main.rb, line 15 def read_build build_str = @source.read JSON.parse(build_str) rescue JSON::ParserError => e puts e nil end
run()
click to toggle source
# File lib/code_build_tail/main.rb, line 23 def run build_hash = read_build if build_hash.nil? puts "Unable to parse build" return 1 end unless build_hash.key?("build") && build_hash["build"].key?("id") puts "Parsed build json, but no id field" return 1 end @build = CodeBuildTail::Build.new(Aws::CodeBuild::Client.new, build_hash["build"]["id"]) follow_build end
sleep_time()
click to toggle source
# File lib/code_build_tail/main.rb, line 60 def sleep_time 5 + @build.refresh_count end