Skip to content

Instantly share code, notes, and snippets.

@pgr0ss
Created February 28, 2010 18:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgr0ss/317709 to your computer and use it in GitHub Desktop.
Save pgr0ss/317709 to your computer and use it in GitHub Desktop.
class RequestProcessor
@queue = :requests
APP = Rack::Builder.new do
use Rails::Rack::Static
use Rack::CommonLogger
run ActionController::Dispatcher.new
end
RACK_BASE_REQUEST = {
"PATH_INFO"=>"/things",
"QUERY_STRING"=>"",
"REQUEST_METHOD"=>"GET",
"SERVER_NAME"=>"localhost",
"SERVER_PORT"=>"3000",
"rack.errors" => STDERR,
"rack.input" => StringIO.new(""),
"rack.multiprocess"=>true,
"rack.multithread" => false,
"rack.run_once" => false,
"rack.url_scheme" => "http",
"rack.version"=>[1, 0],
}
def self.perform(hash)
url = hash.delete("url")
request = RACK_BASE_REQUEST.clone
request["PATH_INFO"] = url
response = APP.call(request)
body = ""
response.last.each { |part| body << part }
hash["body"] = URI.escape(body)
cmd = "redis-cli rpush responses #{hash.to_json.inspect}"
system cmd
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment