lib/buildbox/worker.rb in buildbox-0.0.4 vs lib/buildbox/worker.rb in buildbox-0.1
- old
+ new
@@ -1,21 +1,37 @@
module Buildbox
class Worker
- def process
- if scheduled = api.builds.payload.first
- start Build.new(scheduled)
+ def initialize(access_token)
+ @access_token = access_token
+ end
+
+ def start
+ loop do
+ projects.each do |project|
+ running_builds = api.scheduled_builds(project).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)
+
+ sleep 5
+ end
end
end
private
- def start(build)
- api.update_build_state(build.uuid, 'started')
- build.start Buildbox::Observer.new(api, build.uuid)
- api.update_build_state_async(build.uuid, 'finished')
+ def api
+ @api ||= Buildbox::API.new
end
- def api
- @api ||= Buildbox::API.new(:api_key => Buildbox.configuration.api_key)
+ def projects
+ api.worker(:access_token => @access_token, :hostname => hostname).projects
+ end
+
+ def hostname
+ `hostname`.chomp
end
end
end