Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 53 lines (42 sloc) 1.155 kb
3cc1e1e @gdb Initial import of Einhorn
gdb authored
1 #!/usr/bin/env ruby
2 #
3 # An example application using our patched Thin and EventMachine. You
4 # can obtain these from:
5 #
6 # https://github.com/stripe/thin.git, and
7 # https://github.com/stripe/eventmachine.git
8
9 require 'rubygems'
10 require 'einhorn'
11
12 # Make sure we're using the patched versions.
13 gem 'thin', '1.3.2.stripe.0'
14 gem 'eventmachine', '1.0.0.beta.4.stripe.0'
15
16 require 'thin'
17
18 class App
19 def initialize(id)
20 @id = id
21 end
22
23 def call(env)
24 return [200, {}, "[#{$$}] From server instance #{@id}: Got your request!\n"]
25 end
26 end
27
28 def einhorn_main
29 puts "Called with #{ARGV.inspect}"
30
31 if ARGV.length == 0
32 raise "Need to call with at least one argument. Try running 'einhorn #{$0} srv:127.0.0.1:5000,r,n srv:127.0.0.1:5001,r,n' and then running 'curl 127.0.0.1:5000' or 'curl 127.0.0.1:5001'"
33 end
34
35 Einhorn::Worker.graceful_shutdown do
36 puts "#{$$} is now exiting..."
37 exit(0)
38 end
39 Einhorn::Worker.ack!
40
41 EventMachine.run do
42 ARGV.each_with_index do |arg, i|
43 sock = Integer(arg)
44 srv = Thin::Server.new(sock, App.new(i), :reuse => true)
45 srv.start
46 end
47 end
48 end
49
50 if $0 == __FILE__
51 einhorn_main
52 end
Something went wrong with that request. Please try again.