lib/buildbox/client.rb in buildbox-0.0.1 vs lib/buildbox/client.rb in buildbox-0.0.2

- old
+ new

@@ -8,19 +8,23 @@ def start exit_if_already_running Buildbox.logger.info "Starting client..." + register_client + begin daemonize if @options[:daemon] pid_file.save loop do reload_configuration process_build_queue wait_for_interval end + rescue => e + api.crash(e, :build => @build) ensure pid_file.delete end end @@ -34,29 +38,39 @@ def daemonize if @options[:daemon] Process.daemon - Buildbox.logger = Logger.new(Buildbox.root_path.join("ci.log")) + Buildbox.logger = Logger.new(Buildbox.root_path.join("buildbox.log")) end end + def register_client + worker_uuid = Buildbox.configuration.worker_uuid + response = api.register(:uuid => worker_uuid, :hostname => `hostname`.chomp) + Buildbox.configuration.update :worker_uuid, response.payload[:uuid] + end + def process_build_queue - build = api.scheduled(:repositories => Buildbox.configuration.repositories).first + scheduled = api.builds.payload.first - Buildbox::Worker.new(build, api).run if build + if scheduled + # store build in an instance variable so we can report on it in + # the event of a crash + @build = Build.new(scheduled) + Buildbox::Worker.new(@build, api).run + @build = nil + end end def reload_configuration - Buildbox.logger.info "Reloading configuration" - Buildbox.configuration.reload end def wait_for_interval - Buildbox.logger.info "Sleeping for #{@interval} seconds" + Buildbox.logger.debug "Sleeping for #{@interval} seconds" sleep(@interval) end def exit_if_already_running @@ -66,10 +80,10 @@ exit 1 end end def api - @api ||= Buildbox::API.new + @api ||= Buildbox::API.new(:api_key => Buildbox.configuration.api_key) end def pid_file @pid_file ||= Buildbox::PidFile.new end