Class: CodeBuildTail::Main
- Inherits:
-
Object
- Object
- CodeBuildTail::Main
- Defined in:
- lib/code_build_tail/main.rb
Instance Method Summary collapse
- #follow_build ⇒ Object
-
#initialize(source) ⇒ Main
constructor
A new instance of Main.
- #read_build ⇒ Object
- #run ⇒ Object
- #sleep_time ⇒ Object
Constructor Details
#initialize(source) ⇒ Main
Returns a new instance of Main.
10 11 12 13 |
# 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 |
Instance Method Details
#follow_build ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
15 16 17 18 19 20 21 |
# 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 ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Object
60 61 62 |
# File 'lib/code_build_tail/main.rb', line 60 def sleep_time 5 + @build.refresh_count end |