Sha256: 37a546271574755d032202f194c81c268a3211203e23552e56bc7be126431792

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 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, 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

1 entries across 1 versions & 1 rubygems

Version Path
buildbox-0.2.1 lib/buildbox/worker.rb