Class: RailsSCGIProcessor

Inherits:
SCGI::Processor
  • Object
show all
Defined in:
lib/style/handler/scgi.rb

Overview

This SCGI::Processor subclass hooks the SCGI request into Ruby on Rails.

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ RailsSCGIProcessor

Initialzes Rails with the appropriate environment and settings



29
30
31
32
33
34
35
36
# File 'lib/style/handler/scgi.rb', line 29

def initialize(settings)
  $0 += " environment:#{ENV['RAILS_ENV'] = settings[:environment] || 'production'}"
  require 'config/environment'
  ActiveRecord::Base.allow_concurrency = false
  require 'dispatcher'
  super(settings)
  @guard = Mutex.new
end

Instance Method Details

#process_request(request, body, socket) ⇒ Object

Submits requests to Rails in a single threaded fashion



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/style/handler/scgi.rb', line 39

def process_request(request, body, socket)
  return if socket.closed?
  cgi = SCGI::CGIFixed.new(request, body, socket)
  begin
    @guard.synchronize{Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, cgi.stdoutput)}
  rescue IOError
    @log.error("received IOError #$! when handling client.  Your web server doesn't like me.")
  rescue Object => rails_error
    @log.error("calling Dispatcher.dispatch", rails_error)
  end
end