Sha256: 097cd35350115a8939bc96353d0dcbf88f6bb728bcdb6685fb75b2acdabbd776

Contents?: true

Size: 910 Bytes

Versions: 2

Compression:

Stored size: 910 Bytes

Contents

require 'rubygems'
require 'celluloid'

module Buildbox
  class Worker
    include Celluloid::Logger

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

    def work
      running_builds = scheduled_builds.map do |build|
        Monitor.new(build, @api).async.monitor
        Runner.new(build).future(:start)
      end

      # wait for all the running builds to finish
      running_builds.map(&:value)
    end

    private

    def projects
      @api.worker(:access_token => @access_token, :hostname => hostname).projects
    rescue Faraday::Error::ClientError
      warn "Worker #{@access_token} doesn't exist"
      [] # return empty array to avoid breakage
    end

    def scheduled_builds
      projects.map do |project|
        @api.scheduled_builds(project)
      end.flatten
    end

    def hostname
      `hostname`.chomp
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
buildbox-0.2 lib/buildbox/worker.rb
buildbox-0.1.4 lib/buildbox/worker.rb