Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 54 lines (42 sloc) 1.183 kb
#!/usr/bin/env ruby
#
# An example application using our patched Thin and EventMachine. You
# can obtain these from:
#
# https://github.com/stripe/thin.git, and
# https://github.com/stripe/eventmachine.git
require 'rubygems'
require 'einhorn'
# Make sure we're using the patched versions.
gem 'thin', '1.3.2.stripe.0'
gem 'eventmachine', '1.0.0.beta.4.stripe.0'
require 'thin'
class App
def initialize(id)
@id = id
end
def call(env)
return [200, {}, "[#{$$}] From server instance #{@id}: Got your request!\n"]
end
end
def einhorn_main
puts "Called with #{ARGV.inspect}"
einhorn_fds = Einhorn::Worker.einhorn_fds
unless einhorn_fds
raise "Need to call with at least one bound socket. Try running 'einhorn -b 127.0.0.1:5000,r,n -b 127.0.0.1:5001,r,n #{$0}' and then running 'curl 127.0.0.1:5000' or 'curl 127.0.0.1:5001'"
end
Einhorn::Worker.graceful_shutdown do
puts "#{$$} is now exiting..."
exit(0)
end
Einhorn::Worker.ack!
EventMachine.run do
einhorn_fds.each_with_index do |sock, i|
srv = Thin::Server.new(sock, App.new(i), :reuse => true)
srv.start
end
end
end
if $0 == __FILE__
einhorn_main
end
Jump to Line
Something went wrong with that request. Please try again.