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 implementation #401

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
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ gem 'http_accept_language'
# Routes for JS files
gem 'js-routes', '~> 1.1.0'

# Use Puma as the app server
gem 'puma'

group :test do
# Easier test writing
gem "shoulda-matchers", '~> 2.8.0'
Expand All @@ -80,8 +83,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
11 changes: 3 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ GEM
mime-types (>= 1.16, < 3)
nokogiri (~> 1.5)
rails (>= 3, < 5)
daemons (1.2.3)
dalli (2.7.4)
database_cleaner (1.5.0)
debug_inspector (0.0.2)
Expand All @@ -109,7 +108,6 @@ GEM
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
erubis (2.7.0)
eventmachine (1.0.8)
exception_notification (4.1.1)
actionmailer (>= 3.0.4)
activesupport (>= 3.0.4)
Expand Down Expand Up @@ -216,6 +214,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 @@ -302,10 +301,6 @@ GEM
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thin (1.6.4)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (~> 1.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
Expand Down Expand Up @@ -371,6 +366,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 @@ -384,10 +380,9 @@ DEPENDENCIES
sprockets
sqlite3
therubyracer
thin
turbolinks
uglifier (>= 1.3.0)
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
15 changes: 11 additions & 4 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ def state
# POST /projects/1/repositories/1/state_with_date
def state_with_date
year, month, day = params[:year], params[:month], params[:day]
@processing = @repository.processing_with_date("#{year}-#{month}-#{day}")

respond_to_processing_state
begin
@processing = @repository.processing_with_date("#{year}-#{month}-#{day}")
rescue
ensure
respond_to_processing_state
end
end

# GET /projects/1/repositories/1/process
Expand Down Expand Up @@ -172,7 +175,11 @@ def create_and_redir(format)

def respond_to_processing_state
respond_to do |format|
if @processing.state == 'READY'
if @processing.nil?
@processing = @repository.last_processing
@processing.state = 'ERROR'
format.js { render action: 'load_error' }
elsif @processing.state == 'READY'
format.js { render action: 'load_ready_processing' }
elsif @processing.state == 'ERROR'
format.js { render action: 'load_error' }
Expand Down
21 changes: 0 additions & 21 deletions config/initializers/konacha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,4 @@
config.driver = :poltergeist
end

# 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
class << self
old_run = instance_method(:run)

define_method(:run) do
prev_server = Capybara.server
begin
Capybara.server do |app, port|
require 'rack/handler/thin'
Rack::Handler::Thin.run(app, :Port => port)
end
old_run.bind(self).call
ensure
Capybara.server(&prev_server)
end
end
end
end
end
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