Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puma server #405

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ gem 'http_accept_language'
# Routes for JS files
gem 'js-routes', '~> 1.1.0'

# Use Puma webserver for the application.
gem 'puma'

group :test do

# Use Thin webserver for konacha tests.
gem 'thin'

# Easier test writing
gem "shoulda-matchers", '~> 2.8.0'

Expand All @@ -80,8 +87,6 @@ group :test do
# Test coverage report
gem 'codeclimate-test-reporter', require: nil

# For Konacha
gem 'thin'
end

# Startup script generation (server process manager)
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ GEM
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
puma (3.8.2)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -371,6 +372,7 @@ DEPENDENCIES
mocha
pg (~> 0.18.1)
poltergeist (~> 1.7.0)
puma
rails (= 4.2.4)
rails-html-sanitizer (~> 1.0)
railsstrap (~> 3.3.4)
Expand All @@ -390,4 +392,4 @@ DEPENDENCIES
web-console (~> 2.0.0)

BUNDLED WITH
1.11.2
1.14.6
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: bundle exec rails s -p $PORT -e $RAILS_ENV
web: bundle exec puma -C config/puma.rb
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true

require "#{Rails.root}/lib/core_extensions/rack/handler"

end
end
2 changes: 1 addition & 1 deletion config/initializers/konacha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
config.driver = :poltergeist
end

# Use thin to run Konacha tests. This is needed because the tests hang frequently in Travis using the default (WEBRick)
# Use Thin to run Konacha tests. This is needed because the tests hang frequently in Travis using the default (WEBRick)
# We can't just do 'Capybara.server' in the configure block because it will also apply to anything else run by
# Capybara. So instead, override the Konacha.run method to change the server, and restore it after completion.
module Konacha
Expand Down
Empty file added config/initializers/rack.rb
Empty file.
15 changes: 15 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
15 changes: 15 additions & 0 deletions lib/core_extensions/rack/handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Monkey Patch for Rack to choose Puma as the default webserver.
# Without this, Thin takes precedence over Puma.
# Removing Thin would make this unnecessary. However, Thin is needed for Konacha.

module Rack
require 'rack/handler/puma'

module Handler

def self.default argument
return Rack::Handler::Puma
end

end
end
12 changes: 12 additions & 0 deletions spec/lib/core_extensions/rack/handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'
require "#{Rails.root}/lib/core_extensions/rack/handler"

RSpec.describe Rack::Handler do

describe 'default webserver' do
it 'should be puma' do
argument = 'argument'
expect(Rack::Handler.default argument).to eq(Rack::Handler::Puma)
end
end
end