Class: RackRabbit::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-rabbit/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Handler




12
13
14
15
16
# File 'lib/rack-rabbit/handler.rb', line 12

def initialize(app, config)
  @app    = app
  @config = config
  @logger = config.logger
end

Instance Attribute Details

#appObject (readonly)




8
9
10
# File 'lib/rack-rabbit/handler.rb', line 8

def app
  @app
end

#configObject (readonly)




8
9
10
# File 'lib/rack-rabbit/handler.rb', line 8

def config
  @config
end

#loggerObject (readonly)




8
9
10
# File 'lib/rack-rabbit/handler.rb', line 8

def logger
  @logger
end

Instance Method Details

#handle(message) ⇒ Object




20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rack-rabbit/handler.rb', line 20

def handle(message)

  env = message.get_rack_env(config.rack_env)

  status, headers, body_chunks = app.call(env)

  body = []
  body_chunks.each{|c| body << c }
  body_chunks.close if body_chunks.respond_to?(:close)

  Response.new(status, headers, body.join)

rescue Exception => e    # don't let exceptions bubble out of worker process

  logger.error e
  logger.error e.backtrace.join("\n")

  Response.new(500, {}, "Internal Server Error")

end