Class: QueueingProxy::Frontend

Inherits:
Object
  • Object
show all
Defined in:
lib/queueing_proxy/frontend.rb

Defined Under Namespace

Classes: FakeBackend, Queuer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, host, port, backends) ⇒ Frontend

Returns a new instance of Frontend.



5
6
7
8
# File 'lib/queueing_proxy/frontend.rb', line 5

def initialize(logger, host, port, backends)
  @logger, @host, @port, @backends = logger, host, port, backends
  logger.info "Starting queuer on #{host}:#{port} using beanstalk at #{backends.map{|b| "#{b.tube}@#{b.host}"}.join(', ')}"
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/queueing_proxy/frontend.rb', line 3

def logger
  @logger
end

Instance Method Details

#beanstalksObject



10
11
12
13
14
15
16
# File 'lib/queueing_proxy/frontend.rb', line 10

def beanstalks
  @beanstalks ||= @backends.map {|b|
    connection = EMJack::Connection.new(:host => b.host, :tube => b.tube)
    connection.errback { logger.error "Couldn't connect to beanstalk" }
    connection
  }
end

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/queueing_proxy/frontend.rb', line 18

def run
  app = proc do |env|
    logger.info "Frontend frontend #{env['HTTP_VERSION']} #{env['PATH_INFO']} #{env['REQUEST_METHOD']}"
    [200, {}, []]
  end
  backend = FakeBackend.new

  EM.start_server(@host, @port, Queuer) do |conn|
    conn.beanstalks = beanstalks
    conn.app = app
    conn.backend = backend
    conn.logger = logger
  end
end