Sha256: e725cbc2918132afc82765bfa6aeb5456ec2ecb27bf668168f41f814da29dfbc

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

#!/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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
einhorn-0.4.2 example/thin_example
einhorn-0.4.1 example/thin_example
einhorn-0.4.0 example/thin_example