diff --git a/Gemfile b/Gemfile index c9bbcc42..9db2f914 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: # TODO need to release the gem as soon i'm certain this change makes sense gem 'simple_states', github: 'svenfuchs/simple_states', branch: 'sf-set-state-early' -gem 'puma' +gem 'puma', '1.6.3' gem "sentry-raven", github: 'getsentry/raven-ruby' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' @@ -21,9 +21,9 @@ gem 'gh', github: 'rkh/gh' gem 'bunny' gem 'dalli' gem 'pry' -gem 'metriks', '0.9.9.2' +gem 'metriks', '0.9.9.2' -gem 'ar-octopus', github: 'travis-ci/octopus', require: 'octopus' +gem 'ar-octopus', github: 'travis-ci/octopus', require: 'octopus' group :test do gem 'rspec', '~> 2.11' diff --git a/Gemfile.lock b/Gemfile.lock index 79bfffa6..0916dfe0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,10 @@ GIT remote: git://github.com/getsentry/raven-ruby.git - revision: e520389a56d099276c167d8b442967c7fa549ecd + revision: 267b33417a3ed43f552911cf353561a641ba9fb2 specs: - sentry-raven (0.4.3) + sentry-raven (0.4.6) faraday (>= 0.7.6) - hashie + hashie (>= 1.1.0) multi_json (~> 1.0) uuidtools @@ -17,9 +17,9 @@ GIT GIT remote: git://github.com/rkh/gh.git - revision: c14f7619d24ff3aa156dae1ec3e6bd1f2734cd61 + revision: ff93c759591a66c9d5250cada5234d2adde95dd3 specs: - gh (0.11.0) + gh (0.11.1) addressable backports faraday (~> 0.8) @@ -53,7 +53,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 75986691f25bd5533fa812dbe81638c7d1da3651 + revision: d3f5fd82fe81f5bfa97d810f90838a1dbeda6e17 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -82,7 +82,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: db10b27101763f39d46075ded19bcf4bb845b1ff + revision: 1f705a2ce4bcc42c642b337f117073abedef971b specs: travis-support (0.0.1) @@ -98,7 +98,7 @@ PATH travis-api (0.0.1) backports (~> 2.5) hubble (~> 0.1) - newrelic_rpm (~> 3.6.1.85.beta) + newrelic_rpm (~> 3.6.1.88) pg (~> 0.13.2) rack-contrib (~> 1.1) rack-ssl (~> 1.3, >= 1.3.3) @@ -138,7 +138,7 @@ GEM multi_json (~> 1.0) addressable (2.3.4) arel (3.0.2) - atomic (1.1.7) + atomic (1.1.8) avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) @@ -155,17 +155,20 @@ GEM activerecord rake database_cleaner (0.8.0) - diff-lcs (1.2.1) + diff-lcs (1.2.4) + dotenv (0.7.0) erubis (2.7.0) - eventmachine (1.0.0) - facter (1.6.17) + eventmachine (1.0.3) + facter (1.7.0) factory_girl (2.4.2) activesupport faraday (0.8.7) multipart-post (~> 1.1) - foreman (0.61.0) + ffi (1.8.1) + foreman (0.63.0) + dotenv (>= 0.7) thor (>= 0.13.6) - hashie (2.0.0) + hashie (2.0.4) hashr (0.0.22) hike (1.2.2) hitimes (1.2.1) @@ -174,7 +177,10 @@ GEM i18n (0.6.1) journey (1.0.4) json (1.7.7) - listen (0.7.2) + listen (1.0.3) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + rb-kqueue (>= 0.2) mail (2.5.3) i18n (>= 0.4.0) mime-types (~> 1.16) @@ -185,8 +191,8 @@ GEM atomic (~> 1.0) avl_tree (~> 1.1.2) hitimes (~> 1.1) - mime-types (1.22) - mocha (0.13.2) + mime-types (1.23) + mocha (0.13.3) metaclass (~> 0.0.1) multi_json (1.7.2) multipart-post (1.2.0) @@ -195,7 +201,7 @@ GEM newrelic_rpm (3.6.1.88) pg (0.13.2) polyglot (0.3.3) - pry (0.9.12) + pry (0.9.12.1) coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) @@ -222,30 +228,34 @@ GEM thor (>= 0.14.6, < 2.0) rake (0.9.6) rb-fsevent (0.9.3) + rb-inotify (0.9.0) + ffi (>= 0.5.0) + rb-kqueue (0.2.0) + ffi (>= 0.5.0) rdoc (3.12.2) json (~> 1.4) redcarpet (2.2.2) - redis (3.0.3) + redis (3.0.4) redis-namespace (1.2.1) redis (~> 3.0.0) - rerun (0.8.0) - listen + rerun (0.8.1) + listen (>= 1.0.3) rollout (1.1.0) rspec (2.13.0) rspec-core (~> 2.13.0) rspec-expectations (~> 2.13.0) rspec-mocks (~> 2.13.0) - rspec-core (2.13.0) + rspec-core (2.13.1) rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.13.0) + rspec-mocks (2.13.1) sidekiq (2.5.4) celluloid (~> 0.12.0) connection_pool (~> 0.9.2) multi_json (~> 1) redis (~> 3) redis-namespace - signature (0.1.6) + signature (0.1.7) sinatra (1.3.6) rack (~> 1.4) rack-protection (~> 1.3) @@ -257,7 +267,7 @@ GEM rack-test sinatra (~> 1.3.0) tilt (~> 1.3) - slop (3.4.3) + slop (3.4.4) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -274,9 +284,9 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) - uuidtools (2.1.3) + uuidtools (2.1.4) yajl-ruby (1.1.0) - yard (0.8.4.1) + yard (0.8.6.1) PLATFORMS ruby @@ -293,7 +303,7 @@ DEPENDENCIES micro_migrations! mocha (~> 0.12) pry - puma + puma (= 1.6.3) rack-cache (~> 1.2) rack-contrib! rake (~> 0.9.2) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 6cf214f2..93073d44 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -118,24 +118,8 @@ module Travis::Api def self.setup_travis Travis::Amqp.config = Travis.config.amqp - Travis::Database.connect - if Travis.env == 'production' || Travis.env == 'staging' - # Octopus checks for Rails.env, just hardcode enabled? - Octopus.instance_eval do - def enabled? - true - end - end - - ActiveRecord::Base.custom_octopus_connection = false - - ::Octopus.setup do |config| - config.shards = { :follower => Travis.config.database_follower } - config.environments = ['production', 'staging'] - end - - end + setup_database_connections Travis::Features.start @@ -155,6 +139,28 @@ module Travis::Api end end + def self.setup_database_connections + Travis::Database.connect + + return unless Travis.config.use_database_follower? + + if Travis.env == 'production' || Travis.env == 'staging' + # Octopus checks for Rails.env, just hardcode enabled? + Octopus.instance_eval do + def enabled? + true + end + end + + ActiveRecord::Base.custom_octopus_connection = false + + ::Octopus.setup do |config| + config.shards = { :follower => Travis.config.database_follower } + config.environments = ['production', 'staging'] + end + end + end + def self.load_endpoints Backports.require_relative_dir 'app/middleware' Backports.require_relative_dir 'app/endpoint' diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 2716ff13..11c82afc 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -10,7 +10,7 @@ class Travis::Api::App set(:prefix) { "/" << name[/[^:]+$/].underscore } set disable_root_endpoint: false register :scoping - helpers :current_user, :flash + helpers :current_user, :flash, :db_follower # TODO hmmm? before { flash.clear } diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index 6e36e104..e1db9bb5 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -52,7 +52,7 @@ class Travis::Api::App # # json(:repository) get '/:owner_name/:name' do - Octopus.using(:follower) do + prefer_follower do respond_with service(:find_repo, params) end end diff --git a/lib/travis/api/app/helpers/db_follower.rb b/lib/travis/api/app/helpers/db_follower.rb new file mode 100644 index 00000000..4658aca2 --- /dev/null +++ b/lib/travis/api/app/helpers/db_follower.rb @@ -0,0 +1,13 @@ +require 'travis/api/app' + +class Travis::Api::App + module Helpers + module DbFollower + def prefer_follower + Octopus.using(:follower) do + yield + end + end + end + end +end diff --git a/travis-api.gemspec b/travis-api.gemspec index 9d883c1f..4fdfb215 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -189,7 +189,7 @@ Gem::Specification.new do |s| s.add_dependency 'hubble', '~> 0.1' s.add_dependency 'backports', '~> 2.5' s.add_dependency 'pg', '~> 0.13.2' - s.add_dependency 'newrelic_rpm', '~> 3.6.1.85.beta' + s.add_dependency 'newrelic_rpm', '~> 3.6.1.88' s.add_dependency 'thin', '~> 1.4' s.add_dependency 'sinatra', '~> 1.3' s.add_dependency 'sinatra-contrib', '~> 1.3'