Sha256: 1d1d541f5092d6111464e96c88923bfdfe1281ba11b5e26638ae5127ec6e8a21

Contents?: true

Size: 911 Bytes

Versions: 4

Compression:

Stored size: 911 Bytes

Contents

require 'celluloid'

module Buildbox
  class Server
    INTERVAL = 5

    def initialize(config = Buildbox.config, logger = Buildbox.logger)
      @config      = config
      @logger      = logger
      @supervisors = []
    end

    def start
      Celluloid.logger = @logger
      Celluloid::Actor[:artifact_poster_pool] = Artifact::Poster.pool

      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.process
        end

        wait INTERVAL
      end
    end

    private

    def wait(interval)
      @logger.debug "Sleeping for #{interval} seconds"

      sleep interval
    end

    def agent_access_tokens
      @config.agent_access_tokens
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
buildbox-0.6.2 lib/buildbox/server.rb
buildbox-0.6.1 lib/buildbox/server.rb
buildbox-0.6 lib/buildbox/server.rb
buildbox-0.6.beta3 lib/buildbox/server.rb