From 8ef9ef06f385130ed7cc2b13b107b15d599414f2 Mon Sep 17 00:00:00 2001 From: Tony Mai Date: Fri, 15 May 2015 14:01:02 -0400 Subject: [PATCH 1/4] remove sqlite3 and activerecord --- Gemfile | 1 - Gemfile.lock | 2 -- config/application.rb | 4 ---- config/database.yml | 25 ------------------------- config/environments/development.rb | 3 --- config/environments/production.rb | 3 --- 6 files changed, 38 deletions(-) delete mode 100644 config/database.yml diff --git a/Gemfile b/Gemfile index b2e28ba..531e57d 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.1' -gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index d2af9d2..0da1fc3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -182,7 +182,6 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.10) thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) @@ -228,7 +227,6 @@ DEPENDENCIES sass-rails (~> 5.0) sdoc (~> 0.4.0) spring - sqlite3 twilio-ruby uglifier (>= 1.3.0) web-console (~> 2.0) diff --git a/config/application.rb b/config/application.rb index 03551a0..c634ee0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,7 +4,6 @@ # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" -require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "action_view/railtie" @@ -28,8 +27,5 @@ class Application < Rails::Application # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de - - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true end end diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index 1c1a37c..0000000 --- a/config/database.yml +++ /dev/null @@ -1,25 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -# -default: &default - adapter: sqlite3 - pool: 5 - timeout: 5000 - -development: - <<: *default - database: db/development.sqlite3 - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - <<: *default - database: db/test.sqlite3 - -production: - <<: *default - database: db/production.sqlite3 diff --git a/config/environments/development.rb b/config/environments/development.rb index b55e214..0feba2e 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -19,9 +19,6 @@ # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise an error on page load if there are pending migrations. - config.active_record.migration_error = :page_load - # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e..a008b61 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,7 +73,4 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new - - # Do not dump schema after migrations. - config.active_record.dump_schema_after_migration = false end From e3f1af35532a6022585af7655189da6b2990739a Mon Sep 17 00:00:00 2001 From: Tony Mai Date: Fri, 15 May 2015 14:49:31 -0400 Subject: [PATCH 2/4] update production redirect_uri for oath2 --- app/controllers/oauth2_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/oauth2_controller.rb b/app/controllers/oauth2_controller.rb index d9d87e7..3d37d62 100644 --- a/app/controllers/oauth2_controller.rb +++ b/app/controllers/oauth2_controller.rb @@ -13,7 +13,7 @@ def callback client_secret: ENV['UBER_SECRET'], client_id: ENV['UBER_CLIENT_ID'], grant_type: 'authorization_code', - redirect_uri: 'http://localhost:3000/oauth2/callback', + redirect_uri: "#{ENV['REDIRECT_URI'] || 'http://localhost:3000'}/oauth2/callback", code: params[:code] }) access_token = response["access_token"] refresh_token = response["refresh_token"] From 392a04e5890b1a791b14d0d6eb40716506c81c07 Mon Sep 17 00:00:00 2001 From: Tony Mai Date: Fri, 15 May 2015 16:03:10 -0400 Subject: [PATCH 3/4] change server to unicorn and add redis production settings --- Gemfile | 2 +- Gemfile.lock | 7 +++++++ Procfile | 2 ++ config/initializers/redis.rb | 3 +++ config/unicorn.rb | 29 +++++++++++++++++++++++++++++ lib/tasks/resque.rake | 3 ++- 6 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Procfile create mode 100644 config/initializers/redis.rb create mode 100644 config/unicorn.rb diff --git a/Gemfile b/Gemfile index 531e57d..23b694b 100644 --- a/Gemfile +++ b/Gemfile @@ -25,7 +25,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc # gem 'bcrypt', '~> 3.1.7' # Use Unicorn as the app server -# gem 'unicorn' +gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development diff --git a/Gemfile.lock b/Gemfile.lock index 0da1fc3..f10e0fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -86,6 +86,7 @@ GEM thor (>= 0.14, < 2.0) json (1.8.2) jwt (1.4.1) + kgio (2.9.3) loofah (2.0.1) nokogiri (>= 1.5.9) mail (2.6.3) @@ -138,6 +139,7 @@ GEM activesupport (= 4.2.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.13.0) rake (10.4.2) rdoc (4.2.0) json (~> 1.4) @@ -194,6 +196,10 @@ GEM uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) + unicorn (4.9.0) + kgio (~> 2.6) + rack + raindrops (~> 0.7) vegas (0.1.11) rack (>= 1.0.0) web-console (2.1.2) @@ -229,4 +235,5 @@ DEPENDENCIES spring twilio-ruby uglifier (>= 1.3.0) + unicorn web-console (~> 2.0) diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..48d80ac --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb +resque: env TERM_CHILD=1 QUEUE=* bundle exec rake resque:work \ No newline at end of file diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb new file mode 100644 index 0000000..8224c3e --- /dev/null +++ b/config/initializers/redis.rb @@ -0,0 +1,3 @@ +if ENV["REDISCLOUD_URL"] + $redis = Resque.redis = Redis.new(:url => ENV["REDISCLOUD_URL"]) +end \ No newline at end of file diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..b638a25 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,29 @@ +worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) +timeout 15 +preload_app true + + +before_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn master intercepting TERM and sending myself QUIT instead' + Process.kill 'QUIT', Process.pid + end + + defined?(ActiveRecord::Base) and + ActiveRecord::Base.connection.disconnect! + + if defined?(Resque) + Resque.redis.quit + Rails.logger.info('Disconnected from Redis') + end +end + +after_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' + end + + if defined?(Resque) + Rails.logger.info('Connected to Redis') + end +end \ No newline at end of file diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 3640bca..b59e59b 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -1,4 +1,5 @@ require 'resque/tasks' require 'resque/scheduler/tasks' -task "resque:setup" => :environment \ No newline at end of file +task "resque:setup" => :environment +task "resque:preload" => :environment \ No newline at end of file From a0c04ff1bb62f2803541954124e43a5d736df218 Mon Sep 17 00:00:00 2001 From: Tony Mai Date: Fri, 15 May 2015 16:09:02 -0400 Subject: [PATCH 4/4] update redis config --- app/controllers/events_controller.rb | 1 + config/initializers/redis.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 235f53a..07be12c 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -23,6 +23,7 @@ def create @event.schedule_bg_job redirect_to "/?message=success#upcoming" else + p @event if @event.ride_id? == nil @errors = ['Cannot find rides for departure address','Please make sure it is accurate'] @event.destroy diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb index 8224c3e..5af8d23 100644 --- a/config/initializers/redis.rb +++ b/config/initializers/redis.rb @@ -1,3 +1,3 @@ -if ENV["REDISCLOUD_URL"] - $redis = Resque.redis = Redis.new(:url => ENV["REDISCLOUD_URL"]) +if ENV["REDISTOGO_URL"] + $redis = Resque.redis = Redis.new(:url => ENV["REDISTOGO_URL"]) end \ No newline at end of file