Sha256: 9be7779da73f28cc6d6c51eed9cee7da73ed57bd3592baab73a740bbf7a94ae9

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 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[:uploader_pool] = Uploader.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

1 entries across 1 versions & 1 rubygems

Version Path
buildbox-0.6.beta2 lib/buildbox/server.rb