Sha256: e5a7f6440b0153faa1dcf678dc54531e83fee0a7cf7efbeddbe1ad52f3c0626d

Contents?: true

Size: 936 Bytes

Versions: 1

Compression:

Stored size: 936 Bytes

Contents

require 'celluloid'

module Buildbox
  class Agent
    include Celluloid
    include Celluloid::Logger

    def initialize(access_token, api = Buildbox::API.new)
      @api          = api
      @access_token = access_token
    end

    def process
      return if @current_build

      if @current_build = next_build
        @api.update_build(@access_token, @current_build, :agent_accepted => @access_token)

        Monitor.new(@current_build, @access_token, @api).async.monitor
        Runner.new(@current_build).start
      end

      @current_build = nil
    end

    private

    def next_build
      @api.agent(@access_token, :hostname => hostname, :version => Buildbox::VERSION)
      @api.next_build(@access_token)
    rescue Buildbox::API::AgentNotFoundError
      warn "Agent `#{@access_token}` does not exist"
      [] # return empty array to avoid breakage
    end

    def hostname
      `hostname`.chomp
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buildbox-0.4.2 lib/buildbox/agent.rb