Sha256: 3891e645891d769d089d7bdafa266ffaf0adb3bef0bfc15e8359b467eea2c13e

Contents?: true

Size: 974 Bytes

Versions: 4

Compression:

Stored size: 974 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 work
      builds = scheduled_builds

      # Start off by letting each build know that it's been picked up
      # by an agent.
      builds.each do |build|
        @api.update_build(build, :agent_accepted => @access_token)
      end

      # Run the builds one at a time
      builds.each do |build|
        Monitor.new(build, @api).async.monitor
        Runner.new(build).start
      end
    end

    private

    def scheduled_builds
      agent = @api.agent(@access_token, hostname)
      @api.scheduled_builds agent
    rescue Buildbox::API::AgentNotFoundError
      warn "Agent `#{@access_token}` doesn't exist"
      [] # return empty array to avoid breakage
    end

    def hostname
      `hostname`.chomp
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
buildbox-0.3.7 lib/buildbox/agent.rb
buildbox-0.3.6 lib/buildbox/agent.rb
buildbox-0.3.5 lib/buildbox/agent.rb
buildbox-0.3.4 lib/buildbox/agent.rb