Created
February 28, 2010 18:14
-
-
Save pgr0ss/317709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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