Sha256: 6daaceb1f86a7178791f2cab4e5b093621f8e456298c4f2baa856130575b5361

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

require 'celluloid'

module Buildbox
  class Monitor
    include Celluloid

    def initialize(build, access_token, api)
      @build        = build
      @access_token = access_token
      @api          = api
    end

    def monitor
      loop do
        if @build.started?
          # As the build can finish in between doing the update_build api_call
          # and checking to see if the build has finished, we make sure we use the
          # same finished_at timestamp throughout the entire method.
          finished_at = @build.finished_at

          updated_build = @api.update_build(@access_token, @build, :started_at  => @build.started_at,
                                                                   :finished_at => finished_at,
                                                                   :output      => @build.output,
                                                                   :exit_status => @build.exit_status)

          if updated_build.state == 'canceled' && !@build.cancelling?
            Buildbox::Canceler.new(@build).async.cancel
          end

          break if finished_at
        end

        sleep 1
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
buildbox-0.6.2 lib/buildbox/monitor.rb
buildbox-0.6.1 lib/buildbox/monitor.rb
buildbox-0.6 lib/buildbox/monitor.rb
buildbox-0.6.beta3 lib/buildbox/monitor.rb
buildbox-0.6.beta2 lib/buildbox/monitor.rb
buildbox-0.6.beta1 lib/buildbox/monitor.rb
buildbox-0.5 lib/buildbox/monitor.rb
buildbox-0.4.2 lib/buildbox/monitor.rb
buildbox-0.4.1 lib/buildbox/monitor.rb
buildbox-0.4 lib/buildbox/monitor.rb