lib/buildbox/server.rb in buildbox-0.3.3 vs lib/buildbox/server.rb in buildbox-0.3.4
- old
+ new
@@ -1,31 +1,40 @@
+require 'celluloid'
+
module Buildbox
class Server
INTERVAL = 5
def initialize(config = Buildbox.config, logger = Buildbox.logger)
@config = config
@logger = logger
+ @supervisors = []
end
def start
- loop do
- @config.check
- @config.reload
+ Celluloid.logger = @logger
- agent_access_tokens.each do |access_token|
- Buildbox::Agent.new(access_token, api).work
+ agent_access_tokens.each do |access_token|
+ @supervisors << Buildbox::Agent.supervise(access_token)
+
+ @logger.info "Agent with access token `#{access_token}` has started."
+ end
+
+ loop do
+ @supervisors.each do |supervisor|
+ supervisor.actors.first.async.work
end
- @logger.info "Sleeping for #{INTERVAL} seconds"
- sleep INTERVAL
+ wait INTERVAL
end
end
private
- def api
- @api ||= Buildbox::API.new
+ def wait(interval)
+ @logger.debug "Sleeping for #{interval} seconds"
+
+ sleep interval
end
def agent_access_tokens
@config.agent_access_tokens
end