Sha256: 2c63c017b7c6e05b85fc506206860e5e95d0a75968966fdaf1bb62091db477c0

Contents?: true

Size: 1.18 KB

Versions: 14

Compression:

Stored size: 1.18 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}"
  fd_count = Einhorn::Worker.einhorn_fd_count

  unless fd_count > 0
    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
    (0...fd_count).each do |i|
      sock = Einhorn::Worker.socket!(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

14 entries across 14 versions & 1 rubygems

Version Path
einhorn-0.5.6 example/thin_example
einhorn-0.5.5 example/thin_example
einhorn-0.5.4 example/thin_example
einhorn-0.5.3 example/thin_example
einhorn-0.5.2 example/thin_example
einhorn-0.5.1 example/thin_example
einhorn-0.5.0 example/thin_example
einhorn-0.4.9 example/thin_example
einhorn-0.4.8 example/thin_example
einhorn-0.4.7 example/thin_example
einhorn-0.4.6 example/thin_example
einhorn-0.4.5 example/thin_example
einhorn-0.4.4 example/thin_example
einhorn-0.4.3 example/thin_example