Sha256: baefe4d203fcf0f3d0263c192ac62e9696e77439a2b3dc609beb8637f94ee53f

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 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

      # Run the builds one at a time
      builds.each do |build|
        # Let the agent know that we're about to start working on this build
        @api.update_build(build, :agent_accepted => @access_token)

        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

1 entries across 1 versions & 1 rubygems

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