Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 54 lines (42 sloc) 1.183 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
ba1a2d6 @gdb Update docs and examples for environment variable interface
gdb authored
31 einhorn_fds = Einhorn::Worker.einhorn_fds
32
33 unless einhorn_fds
34 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'"
3cc1e1e @gdb Initial import of Einhorn
gdb authored
35 end
36
37 Einhorn::Worker.graceful_shutdown do
38 puts "#{$$} is now exiting..."
39 exit(0)
40 end
41 Einhorn::Worker.ack!
42
43 EventMachine.run do
ba1a2d6 @gdb Update docs and examples for environment variable interface
gdb authored
44 einhorn_fds.each_with_index do |sock, i|
3cc1e1e @gdb Initial import of Einhorn
gdb authored
45 srv = Thin::Server.new(sock, App.new(i), :reuse => true)
46 srv.start
47 end
48 end
49 end
50
51 if $0 == __FILE__
52 einhorn_main
53 end
Something went wrong with that request. Please try again.