Created
March 26, 2012 10:03
-
-
Save noverloop/2204258 to your computer and use it in GitHub Desktop.
modifications needed to act as buffering reverse proxy on heroku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $stdout.sync = true | |
| require ::File.expand_path('../config/environment', __FILE__) | |
| run AppName::Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'bundler' | |
| $stdout.sync = true | |
| Bundler.require(:rack) | |
| puts ARGV | |
| $port = ARGV.first | |
| SERVERS = 1 | |
| ROOT = '.' | |
| spawn("foreman start worker") | |
| require './proxy' | |
| # Start proxy | |
| BalancingProxy::Server.run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| web: ruby config.ru $PORT | |
| worker: bundle exec thin start -R app_name.ru --socket tmp/thin.sock -e production |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Server | |
| def run(host='0.0.0.0') | |
| puts "Launching proxy at #{host}:#{$port}...\n" | |
| Proxy.start(:host => host, :port => $port, :debug => false) do |conn| | |
| Backend.select do |backend| | |
| @connection_process = Proc.new do |backend,count| | |
| begin | |
| conn.server backend, :socket => backend.socket | |
| conn.on_connect &Callbacks.on_connect | |
| conn.on_data &Callbacks.on_data | |
| conn.on_response &Callbacks.on_response | |
| conn.on_finish &Callbacks.on_finish | |
| rescue RuntimeError | |
| unless count > 4 | |
| EM.add_timer(20) do | |
| @connection_process.call backend, (count+1) | |
| end | |
| end | |
| end | |
| end | |
| @connection_process.call backend, 0 | |
| end | |
| end | |
| end | |
| module_function :run | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment