Class: Buildbox::Monitor

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/buildbox/monitor.rb

Instance Method Summary collapse

Constructor Details

#initialize(build, access_token, api) ⇒ Monitor

Returns a new instance of Monitor.



7
8
9
10
11
# File 'lib/buildbox/monitor.rb', line 7

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

Instance Method Details

#monitorObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/buildbox/monitor.rb', line 13

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