Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9eee295
commit 3198c58
Showing
10 changed files
with
176 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Heroku | ||
module Forward | ||
module Backends | ||
class Base | ||
attr_accessor :application, :socket, :environment, :pid | ||
|
||
def terminate! | ||
return false unless spawned? | ||
Process.kill 'QUIT', @pid | ||
@spawned = false | ||
true | ||
end | ||
|
||
def spawned? | ||
!!@spawned | ||
end | ||
|
||
private | ||
|
||
def check! | ||
raise Heroku::Forward::Errors::MissingBackendOptionError.new('application') unless @application && @application.length > 0 | ||
raise Heroku::Forward::Errors::MissingBackendApplicationError.new(@application) unless File.exists?(@application) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'heroku/forward/backends/base' | ||
|
||
module Heroku | ||
module Forward | ||
module Backends | ||
class Puma < Base | ||
attr_accessor :config_file | ||
|
||
def initialize(options = {}) | ||
@application = options[:application] | ||
@socket = options[:socket] || Heroku::Forward::Utils::Dir.tmp_filename('puma-', '.sock') | ||
@env = options[:env] || 'development' | ||
@config_file = options[:config_file] | ||
end | ||
|
||
def spawn! | ||
return false if spawned? | ||
check! | ||
|
||
args = ['puma'] | ||
args.push '--environment', @env | ||
args.push '--config', @config_file if @config_file | ||
args.push '--bind', "unix://#{@socket}" | ||
args.push @application | ||
|
||
@pid = Spoon.spawnp(*args) | ||
@spawned = true | ||
end | ||
|
||
def terminate! | ||
return false unless spawned? | ||
Process.kill 'QUIT', @pid | ||
@spawned = false | ||
true | ||
end | ||
|
||
def spawned? | ||
!!@spawned | ||
end | ||
|
||
private | ||
|
||
def check! | ||
raise Heroku::Forward::Errors::MissingBackendOptionError.new('application') unless @application && @application.length > 0 | ||
raise Heroku::Forward::Errors::MissingBackendApplicationError.new(@application) unless File.exists?(@application) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'spec_helper' | ||
require 'heroku/forward/backends/puma' | ||
|
||
describe Heroku::Forward::Backends::Puma do | ||
describe "with defaults" do | ||
let(:backend) do | ||
Heroku::Forward::Backends::Puma.new | ||
end | ||
|
||
after do | ||
backend.terminate! | ||
end | ||
|
||
it "#spawned?" do | ||
backend.spawned?.should be_false | ||
end | ||
|
||
context "checks" do | ||
it "checks for application" do | ||
expect { | ||
backend.spawn! | ||
}.to raise_error Heroku::Forward::Errors::MissingBackendOptionError | ||
end | ||
|
||
it "checks that the application file exists" do | ||
expect { | ||
backend.application = 'spec/foobar' | ||
backend.spawn! | ||
}.to raise_error Heroku::Forward::Errors::MissingBackendApplicationError | ||
end | ||
|
||
end | ||
|
||
it "#spawn!" do | ||
backend.application = "spec/support/app.ru" | ||
backend.spawn!.should_not == 0 | ||
sleep 2 | ||
backend.terminate!.should be_true | ||
end | ||
end | ||
|
||
context "constructs command" do | ||
let(:backend) do | ||
Heroku::Forward::Backends::Puma.new( | ||
:application => 'spec/support/app.ru', | ||
:env => 'test', | ||
:socket => '/tmp/puma.sock', | ||
:config_file => 'spec/support/puma.rb' | ||
) | ||
end | ||
|
||
it "forwards arguments to spawner" do | ||
Spoon.should_receive(:spawnp).with(*%w{puma --environment test --config spec/support/puma.rb --bind unix:///tmp/puma.sock spec/support/app.ru}).and_return(0) | ||
backend.spawn! | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
threads 0, 2 |