From a6298f26faf804f3fe8aade9bb981cb68ee9e9d3 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 29 Oct 2012 20:19:42 +0100 Subject: [PATCH 01/21] Bump travis-core --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f6d754b1..ee3d208b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: a55d84819e2f655c7b56472bc62c5037c94bbfc4 + revision: 31f6f9771ecb01629ffafead188efbdd1b28e176 branch: sf-travis-api specs: travis-core (0.0.1) @@ -237,7 +237,7 @@ GEM treetop (1.4.11) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.33) + tzinfo (0.3.34) yard (0.8.3) PLATFORMS From f858f912471496641bb1dc9a8b814ef2af729a9d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 29 Oct 2012 21:31:47 +0100 Subject: [PATCH 02/21] Bump travis-core --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ee3d208b..343b81e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 31f6f9771ecb01629ffafead188efbdd1b28e176 + revision: c2ab45f640efcb0fd1f499c36c55a084aa171de0 branch: sf-travis-api specs: travis-core (0.0.1) @@ -234,7 +234,7 @@ GEM rack (>= 1.0.0) thor (0.14.6) tilt (1.3.3) - treetop (1.4.11) + treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.34) From ec79d9580dc472a4693bbc600aa3224a057df288 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 30 Oct 2012 01:49:03 +0100 Subject: [PATCH 03/21] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 343b81e1..073d403a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: c2ab45f640efcb0fd1f499c36c55a084aa171de0 + revision: df19a126f574cfca7eb782e3e32ae95d4992e2b3 branch: sf-travis-api specs: travis-core (0.0.1) From 37e626291767f1cc138b5547942299badb8e9636 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 1 Nov 2012 00:03:52 +0100 Subject: [PATCH 04/21] Don't show backtraces on errors --- lib/travis/api/app.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 34e458a3..915e212c 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -81,6 +81,12 @@ module Travis::Api # Rack protocol def call(env) app.call(env) + rescue + if Endpoint.production? + [500, {'Content-Type' => 'text/plain'}, ['Travis encountered an error, sorry :(']] + else + raise + end end private From e2b49a91d632e79f07e1036728e253190eab041b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 1 Nov 2012 13:03:08 +0100 Subject: [PATCH 05/21] Use AR's ConnectionManagement before AR::QueryCache (closes #14) --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 915e212c..ddfe2fc9 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -55,6 +55,7 @@ module Travis::Api use Hubble::Rescuer, env: Travis.env, codename: ENV['CODENAME'] if Endpoint.production? && ENV['HUBBLE_ENDPOINT'] use Rack::Protection::PathTraversal use Rack::SSL if Endpoint.production? + use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache if memcache_servers = ENV['MEMCACHE_SERVERS'] @@ -67,7 +68,6 @@ module Travis::Api use Rack::Deflater use Rack::PostBodyContentTypeParser use Rack::JSONP - use ActiveRecord::ConnectionAdapters::ConnectionManagement use Rack::Config do |env| env['travis.global_prefix'] = env['SCRIPT_NAME'] From 505b2fb91177d8f127d1192cd3880b58708fc548 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 1 Nov 2012 16:15:06 +0100 Subject: [PATCH 06/21] No need to revalidate if resource is final --- lib/travis/api/app/responders/service.rb | 2 +- spec/unit/responders/service_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 spec/unit/responders/service_spec.rb diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index 5af8b8fe..bc775195 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -16,7 +16,7 @@ module Travis::Api::App::Responders def cache_control if final? mode = endpoint.public? ? :public : :private - endpoint.expires(31536000, mode, :must_revalidate) # 1 year + endpoint.expires(31536000, mode) # 1 year else # FIXME: Chrome WTF? endpoint.cache_control :no_cache diff --git a/spec/unit/responders/service_spec.rb b/spec/unit/responders/service_spec.rb new file mode 100644 index 00000000..5ee9412f --- /dev/null +++ b/spec/unit/responders/service_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Travis::Api::App::Responders::Service do + class MyService < Travis::Api::App::Responders::Service + end + + let(:endpoint) { stub 'endpoint', public?: true } + let(:resource) { stub 'resource', run: {} } + let(:options) { {} } + let(:service) { MyService.new(endpoint, resource, options) } + + context 'with final resource' do + before { resource.expects(:final?).returns(true) } + + it 'caches resource for a year' do + endpoint.expects(:expires).with(31536000, :public) + service.apply + end + end + +end From b67db360da2213b55f04e06afbe62c0e77b8db18 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 1 Nov 2012 17:28:15 +0100 Subject: [PATCH 07/21] Bump travis-core --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 073d403a..445d742c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: df19a126f574cfca7eb782e3e32ae95d4992e2b3 + revision: 6fc990c32ea2ee48589d736bb2f9a7e254026961 branch: sf-travis-api specs: travis-core (0.0.1) @@ -114,7 +114,7 @@ GEM arel (3.0.2) atomic (1.0.1) avl_tree (1.1.3) - backports (2.6.4) + backports (2.6.5) builder (3.0.4) bunny (0.8.0) coderay (1.0.8) From 1f5001efe70e40ec834eb8bca0680d516ac7cd5a Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Fri, 2 Nov 2012 20:56:16 +0100 Subject: [PATCH 08/21] use travis-core/master --- Gemfile | 2 +- Gemfile.lock | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 86b97759..61f8c729 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gemspec gem 'puma' gem 'travis-support', github: 'travis-ci/travis-support' -gem 'travis-core', github: 'travis-ci/travis-core', branch: 'sf-travis-api' +gem 'travis-core', github: 'travis-ci/travis-core' gem 'hubble', github: 'roidrage/hubble' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' diff --git a/Gemfile.lock b/Gemfile.lock index 445d742c..096e4e31 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,8 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 6fc990c32ea2ee48589d736bb2f9a7e254026961 - branch: sf-travis-api + revision: c8a0672df7e20bc67ed838bdec8b72a2584e9379 specs: travis-core (0.0.1) actionmailer (~> 3.2.3) @@ -153,14 +152,14 @@ GEM mime-types (1.19) mocha (0.12.7) metaclass (~> 0.0.1) - multi_json (1.3.6) + multi_json (1.3.7) multipart-post (1.1.5) net-http-persistent (2.8) net-http-pipeline (1.0.1) newrelic_rpm (3.3.5) pg (0.13.2) polyglot (0.3.3) - postmark (0.9.13) + postmark (0.9.15) json rake postmark-rails (0.4.1) From 889f042cd74d015f727497724c7fd005696e549c Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 5 Nov 2012 02:45:22 +0100 Subject: [PATCH 09/21] bump travis-core --- Gemfile.lock | 4 ++-- spec/integration/v2/hooks_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 096e4e31..fe50b3c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: c8a0672df7e20bc67ed838bdec8b72a2584e9379 + revision: b3e0212aa29ab1042f3357c1cd20b6f9d9fe8e08 specs: travis-core (0.0.1) actionmailer (~> 3.2.3) @@ -236,7 +236,7 @@ GEM treetop (1.4.12) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.34) + tzinfo (0.3.35) yard (0.8.3) PLATFORMS diff --git a/spec/integration/v2/hooks_spec.rb b/spec/integration/v2/hooks_spec.rb index 6e6b8fb6..311e5948 100644 --- a/spec/integration/v2/hooks_spec.rb +++ b/spec/integration/v2/hooks_spec.rb @@ -24,7 +24,7 @@ describe 'Hooks' do let :payload do { :name => 'travis', - :events => ServiceHook::EVENTS, + :events => Travis::Services::Github::SetHook::EVENTS, :active => true, :config => { :user => user.login, :token => user.tokens.first.token, :domain => 'listener.travis-ci.org' } } From b0334527e39dff87a29b80e5d2cac489ebb30c5b Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 5 Nov 2012 16:11:23 +0100 Subject: [PATCH 10/21] bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index fe50b3c9..5c7df026 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: b3e0212aa29ab1042f3357c1cd20b6f9d9fe8e08 + revision: ef4e7c79211e5f0cca022c6612e0a536c7354bce specs: travis-core (0.0.1) actionmailer (~> 3.2.3) From 7695788aae9c065c5d54608de67b4e1786ccc6cf Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 5 Nov 2012 16:17:47 +0100 Subject: [PATCH 11/21] rename EVENTS back after reverting stuff in core --- spec/integration/v2/hooks_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/v2/hooks_spec.rb b/spec/integration/v2/hooks_spec.rb index 311e5948..6e6b8fb6 100644 --- a/spec/integration/v2/hooks_spec.rb +++ b/spec/integration/v2/hooks_spec.rb @@ -24,7 +24,7 @@ describe 'Hooks' do let :payload do { :name => 'travis', - :events => Travis::Services::Github::SetHook::EVENTS, + :events => ServiceHook::EVENTS, :active => true, :config => { :user => user.login, :token => user.tokens.first.token, :domain => 'listener.travis-ci.org' } } From 2f87153df97cf29a05d6af7c7e09ee7d428090d9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 5 Nov 2012 21:45:21 +0100 Subject: [PATCH 12/21] Move CORS middleware in front of the stack If there is an error somewhere along the line (like in DB connection management), it should not interfere with returning proper result for OPTIONS request. Otherwise it's hard to guess why the actual request in the browser was not properly sent. --- lib/travis/api/app.rb | 2 ++ lib/travis/api/app/cors.rb | 20 ++++++++++++++++++++ lib/travis/api/app/middleware/cors.rb | 22 ---------------------- spec/unit/{middleware => }/cors_spec.rb | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 lib/travis/api/app/cors.rb delete mode 100644 lib/travis/api/app/middleware/cors.rb rename spec/unit/{middleware => }/cors_spec.rb (93%) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index ddfe2fc9..049b889b 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -25,6 +25,7 @@ module Travis::Api autoload :Helpers, 'travis/api/app/helpers' autoload :Middleware, 'travis/api/app/middleware' autoload :Responders, 'travis/api/app/responders' + autoload :Cors, 'travis/api/app/cors' Rack.autoload :SSL, 'rack/ssl' @@ -52,6 +53,7 @@ module Travis::Api def initialize @app = Rack::Builder.app do + use Travis::Api::App::Cors use Hubble::Rescuer, env: Travis.env, codename: ENV['CODENAME'] if Endpoint.production? && ENV['HUBBLE_ENDPOINT'] use Rack::Protection::PathTraversal use Rack::SSL if Endpoint.production? diff --git a/lib/travis/api/app/cors.rb b/lib/travis/api/app/cors.rb new file mode 100644 index 00000000..781efc00 --- /dev/null +++ b/lib/travis/api/app/cors.rb @@ -0,0 +1,20 @@ +require 'travis/api/app' + +class Travis::Api::App + # Implements Cross-Origin Resource Sharing. Supported by all major browsers. + # See http://www.w3.org/TR/cors/ + # + # TODO: Be smarter about origin. + class Cors < Base + before do + headers['Access-Control-Allow-Origin'] = "*" + headers['Access-Control-Allow-Credentials'] = "true" + headers['Access-Control-Expose-Headers'] = "Content-Type, Cache-Control, Expires, Etag, Last-Modified" + end + + options // do + headers['Access-Control-Allow-Methods'] = "HEAD, GET, POST, PATCH, PUT, DELETE" + headers['Access-Control-Allow-Headers'] = "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since" + end + end +end diff --git a/lib/travis/api/app/middleware/cors.rb b/lib/travis/api/app/middleware/cors.rb deleted file mode 100644 index 5a93b7a3..00000000 --- a/lib/travis/api/app/middleware/cors.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'travis/api/app' - -class Travis::Api::App - class Middleware - # Implements Cross-Origin Resource Sharing. Supported by all major browsers. - # See http://www.w3.org/TR/cors/ - # - # TODO: Be smarter about origin. - class Cors < Middleware - before do - headers['Access-Control-Allow-Origin'] = "*" - headers['Access-Control-Allow-Credentials'] = "true" - headers['Access-Control-Expose-Headers'] = "Content-Type, Cache-Control, Expires, Etag, Last-Modified" - end - - options // do - headers['Access-Control-Allow-Methods'] = "HEAD, GET, POST, PATCH, PUT, DELETE" - headers['Access-Control-Allow-Headers'] = "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since" - end - end - end -end diff --git a/spec/unit/middleware/cors_spec.rb b/spec/unit/cors_spec.rb similarity index 93% rename from spec/unit/middleware/cors_spec.rb rename to spec/unit/cors_spec.rb index 16d565bd..83e79914 100644 --- a/spec/unit/middleware/cors_spec.rb +++ b/spec/unit/cors_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe Travis::Api::App::Middleware::Cors do +describe Travis::Api::App::Cors do before do mock_app do - use Travis::Api::App::Middleware::Cors + use Travis::Api::App::Cors get('/check_cors') { 'ok' } end end From 0d98576dc7d877f24d077fb7d13660ffae65e21b Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 7 Nov 2012 07:34:13 +0100 Subject: [PATCH 13/21] bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5c7df026..f2e3fa57 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: ef4e7c79211e5f0cca022c6612e0a536c7354bce + revision: d5a1966adfa899690729de2db7be76fdbaad6235 specs: travis-core (0.0.1) actionmailer (~> 3.2.3) From 308ce72aee090bfce5602dc7fe6618e85af451f4 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Wed, 7 Nov 2012 10:43:25 +0100 Subject: [PATCH 14/21] Bump travis-core. Start features on app boot. --- Gemfile | 1 + Gemfile.lock | 32 +++++++++++++++++++++++++++++++- lib/travis/api/app.rb | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 61f8c729..fb20f8dc 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gemspec gem 'puma' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-core', github: 'travis-ci/travis-core' +gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs' gem 'hubble', github: 'roidrage/hubble' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' diff --git a/Gemfile.lock b/Gemfile.lock index f2e3fa57..c13f1a34 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: d5a1966adfa899690729de2db7be76fdbaad6235 + revision: cb999efb7015007423d75df412f076f26d35b09d specs: travis-core (0.0.1) actionmailer (~> 3.2.3) @@ -59,6 +59,14 @@ GIT simple_states (~> 0.1.1) thor (~> 0.14.6) +GIT + remote: git://github.com/travis-ci/travis-sidekiqs.git + revision: 24d6afcc366979de91ee5bf2fbb4b628fc1a3d7a + specs: + travis-sidekiqs (0.0.1) + sentry-raven + sidekiq (~> 2.5.0) + GIT remote: git://github.com/travis-ci/travis-support.git revision: f78d9161369f574f12b9c0c0dbfe13b997766bdd @@ -116,7 +124,11 @@ GEM backports (2.6.5) builder (3.0.4) bunny (0.8.0) + celluloid (0.12.3) + facter (>= 1.6.12) + timers (>= 1.0.0) coderay (1.0.8) + connection_pool (0.9.2) daemons (1.1.9) dalli (2.3.0) data_migrations (0.0.1) @@ -126,12 +138,14 @@ GEM diff-lcs (1.1.3) erubis (2.7.0) eventmachine (1.0.0) + facter (1.6.14) factory_girl (2.4.2) activesupport faraday (0.8.4) multipart-post (~> 1.1) foreman (0.60.2) thor (>= 0.13.6) + hashie (1.2.0) hashr (0.0.22) hike (1.2.1) hitimes (1.1.1) @@ -196,6 +210,8 @@ GEM json (~> 1.4) redcarpet (2.2.2) redis (3.0.2) + redis-namespace (1.2.1) + redis (~> 3.0.0) rerun (0.7.1) listen rollout (1.1.0) @@ -207,6 +223,17 @@ GEM rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.3) + sentry-raven (0.3.1) + faraday (~> 0.8.0.rc2) + hashie + multi_json (~> 1.0) + uuidtools + sidekiq (2.5.2) + celluloid (~> 0.12.0) + connection_pool (~> 0.9.2) + multi_json (~> 1) + redis (~> 3) + redis-namespace signature (0.1.4) simple_states (0.1.1) activesupport @@ -233,10 +260,12 @@ GEM rack (>= 1.0.0) thor (0.14.6) tilt (1.3.3) + timers (1.0.1) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) + uuidtools (2.1.3) yard (0.8.3) PLATFORMS @@ -261,5 +290,6 @@ DEPENDENCIES rspec (~> 2.11) travis-api! travis-core! + travis-sidekiqs! travis-support! yard-sinatra! diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 049b889b..b73e663f 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -104,6 +104,7 @@ module Travis::Api Travis::Amqp.config = Travis.config.amqp Travis::Database.connect Travis.services = Travis::Services + Travis::Features.start end def self.load_endpoints From b07667c52a23f0facb021ade53c5e6d92266c683 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Wed, 7 Nov 2012 10:55:45 +0100 Subject: [PATCH 15/21] Set up sidekiq. --- lib/travis/api/app.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index b73e663f..3957bc35 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -9,6 +9,7 @@ require 'redis' require 'gh' require 'hubble' require 'hubble/middleware' +require 'sidekiq' # Rack class implementing the HTTP API. # Instances respond to #call. @@ -105,6 +106,9 @@ module Travis::Api Travis::Database.connect Travis.services = Travis::Services Travis::Features.start + Sidekiq.client_configure do |config| + config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) + end end def self.load_endpoints From 901d9365319ac91b7419c30e625b101a171d3660 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Wed, 7 Nov 2012 10:59:13 +0100 Subject: [PATCH 16/21] Set up Sidekiq properly. --- .gitignore | 1 + Gemfile | 2 +- lib/travis/api/app.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b977aee1..e09d792f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ config/travis.yml +.yardoc diff --git a/Gemfile b/Gemfile index fb20f8dc..b0e46bfa 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gemspec gem 'puma' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-core', github: 'travis-ci/travis-core' -gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs' +gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil gem 'hubble', github: 'roidrage/hubble' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 3957bc35..3d32d35d 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -106,7 +106,7 @@ module Travis::Api Travis::Database.connect Travis.services = Travis::Services Travis::Features.start - Sidekiq.client_configure do |config| + Sidekiq.configure_client do |config| config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) end end From 612b7f1e9fb87db8afaab24119c63d13e5a6fb24 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Wed, 7 Nov 2012 11:46:43 +0100 Subject: [PATCH 17/21] Switch to sentry for exceptions. --- Gemfile | 2 +- Gemfile.lock | 28 ++++++++++++++-------------- lib/travis/api/app.rb | 6 +++++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index b0e46bfa..9ef26577 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gem 'puma' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil -gem 'hubble', github: 'roidrage/hubble' +gem "sentry-raven", github: 'getsentry/raven-ruby' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' diff --git a/Gemfile.lock b/Gemfile.lock index c13f1a34..20d20678 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,16 @@ GIT specs: micro_migrations (0.0.1) +GIT + remote: git://github.com/getsentry/raven-ruby.git + revision: 5d0e0eacbee39744bdf5b775efb3734d5b4361c7 + specs: + sentry-raven (0.3) + faraday (~> 0.8.0.rc2) + hashie + multi_json (~> 1.0) + uuidtools + GIT remote: git://github.com/rack/rack-contrib.git revision: b7e7c38fd02c3b5da91aa57af78b3f571c6ebcd0 @@ -30,14 +40,6 @@ GIT yard-sinatra (1.0.0) yard (~> 0.7) -GIT - remote: git://github.com/roidrage/hubble.git - revision: f5e6301ac24eabeebaf8f4485d71cdcf93b2f3f8 - specs: - hubble (0.1.2) - faraday - json (~> 1.6) - GIT remote: git://github.com/travis-ci/travis-core.git revision: cb999efb7015007423d75df412f076f26d35b09d @@ -149,6 +151,8 @@ GEM hashr (0.0.22) hike (1.2.1) hitimes (1.1.1) + hubble (0.1.2) + yajl-ruby (~> 1.1) i18n (0.6.1) journey (1.0.4) json (1.7.5) @@ -223,11 +227,6 @@ GEM rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.3) - sentry-raven (0.3.1) - faraday (~> 0.8.0.rc2) - hashie - multi_json (~> 1.0) - uuidtools sidekiq (2.5.2) celluloid (~> 0.12.0) connection_pool (~> 0.9.2) @@ -266,6 +265,7 @@ GEM polyglot (>= 0.3.1) tzinfo (0.3.35) uuidtools (2.1.3) + yajl-ruby (1.1.0) yard (0.8.3) PLATFORMS @@ -278,7 +278,6 @@ DEPENDENCIES factory_girl (~> 2.4.0) foreman gh! - hubble! micro_migrations! mocha (~> 0.12) pry @@ -288,6 +287,7 @@ DEPENDENCIES rake (~> 0.9.2) rerun rspec (~> 2.11) + sentry-raven! travis-api! travis-core! travis-sidekiqs! diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 3d32d35d..0bee284e 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -55,7 +55,7 @@ module Travis::Api def initialize @app = Rack::Builder.app do use Travis::Api::App::Cors - use Hubble::Rescuer, env: Travis.env, codename: ENV['CODENAME'] if Endpoint.production? && ENV['HUBBLE_ENDPOINT'] + use Raven::Rack if Endpoint.production? use Rack::Protection::PathTraversal use Rack::SSL if Endpoint.production? use ActiveRecord::ConnectionAdapters::ConnectionManagement @@ -109,6 +109,10 @@ module Travis::Api Sidekiq.configure_client do |config| config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) end + + Raven.configure do |config| + config.dsn = Travis.config.sentry.dsn + end if Travis.config.sentry end def self.load_endpoints From 3fc6059d0387129595975fdcf579123f2eb5d9bd Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Wed, 7 Nov 2012 11:54:50 +0100 Subject: [PATCH 18/21] require 'raven' --- lib/travis/api/app.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 0bee284e..e50c7d94 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -7,8 +7,7 @@ require 'rack/cache' require 'active_record' require 'redis' require 'gh' -require 'hubble' -require 'hubble/middleware' +require 'raven' require 'sidekiq' # Rack class implementing the HTTP API. From ba364c8188c4ea2545a043a065b12881d7c3442d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 7 Nov 2012 13:40:07 +0100 Subject: [PATCH 19/21] Use unicorn for now, we need to fix concurrency issues to use puma --- Gemfile | 2 +- Gemfile.lock | 10 +++++++--- script/server | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 9ef26577..5d552334 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ ruby '1.9.3' rescue nil source :rubygems gemspec -gem 'puma' +gem 'unicorn' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil diff --git a/Gemfile.lock b/Gemfile.lock index 20d20678..b327cdd3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -156,6 +156,7 @@ GEM i18n (0.6.1) journey (1.0.4) json (1.7.5) + kgio (2.7.4) listen (0.5.3) mail (2.4.4) i18n (>= 0.4.0) @@ -188,8 +189,6 @@ GEM coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.3.1) - puma (1.6.3) - rack (~> 1.2) pusher (0.9.4) multi_json (~> 1.0) signature (~> 0.1.2) @@ -209,6 +208,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) + raindrops (0.10.0) rake (0.9.2.2) rdoc (3.12) json (~> 1.4) @@ -264,6 +264,10 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) + unicorn (4.4.0) + kgio (~> 2.6) + rack + raindrops (~> 0.7) uuidtools (2.1.3) yajl-ruby (1.1.0) yard (0.8.3) @@ -281,7 +285,6 @@ DEPENDENCIES micro_migrations! mocha (~> 0.12) pry - puma rack-cache (~> 1.2) rack-contrib! rake (~> 0.9.2) @@ -292,4 +295,5 @@ DEPENDENCIES travis-core! travis-sidekiqs! travis-support! + unicorn yard-sinatra! diff --git a/script/server b/script/server index a17c4245..29326751 100755 --- a/script/server +++ b/script/server @@ -3,6 +3,6 @@ cd "$(dirname "$0")/.." [ $PORT ] || PORT=3000 [ $RACK_ENV ] || RACK_ENV=development -cmd="ruby -I lib -S bundle exec ruby -I lib -S puma config.ru -p $PORT -e $RACK_ENV --threads 0:16" -[[ $RACK_ENV == "development" ]] && exec rerun "$cmd -b tcp://127.0.0.1:$PORT" +cmd="ruby -I lib -S bundle exec ruby -I lib -S unicorn config.ru -p $PORT -E $RACK_ENV" +[[ $RACK_ENV == "development" ]] && exec rerun "$cmd -l 127.0.0.1:$PORT" exec $cmd From 629a05100e8396aaef2ae802f3085b883345f927 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 7 Nov 2012 15:18:37 +0100 Subject: [PATCH 20/21] Add unicorn config --- config/unicorn.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 config/unicorn.rb diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 00000000..2c751a22 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,23 @@ +# http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/ + +worker_processes 3 # amount of unicorn workers to spin up +timeout 30 # restarts workers that hang for 15 seconds + +preload_app true + +before_fork do |server, worker| + ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base) +end + +after_fork do |server, worker| + require 'travis' + + Travis::Amqp.connect + + ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) + + if $metriks_reporter + $metriks_reporter.stop + $metriks_reporter.start + end +end From 1097eaec7eff82ffac84d5d20d14e7a998c2c427 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 8 Nov 2012 03:13:48 +0100 Subject: [PATCH 21/21] Update travis-core, which fixes PUT /hooks/:id --- Gemfile.lock | 2 +- spec/integration/v2/hooks_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b327cdd3..055ffb2d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,7 +42,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: cb999efb7015007423d75df412f076f26d35b09d + revision: 23c0c1b07f34033e598f02bfd03ec99b01198fce specs: travis-core (0.0.1) actionmailer (~> 3.2.3) diff --git a/spec/integration/v2/hooks_spec.rb b/spec/integration/v2/hooks_spec.rb index 6e6b8fb6..03e61a93 100644 --- a/spec/integration/v2/hooks_spec.rb +++ b/spec/integration/v2/hooks_spec.rb @@ -37,8 +37,9 @@ describe 'Hooks' do it 'sets the hook' do GH.stubs(:[]).returns([]) GH.expects(:post).with(target, payload).returns(GH.load(PAYLOADS[:github][:hook_active])) - put 'hooks', { hook: { id: hook.id, active: 'true' } }, headers + response = put 'hooks', { hook: { id: hook.id, active: 'true' } }, headers repo.reload.active?.should be_true + response.should be_successful end end end