From 057e9f0379fcde9e142058d0de41f39478f50316 Mon Sep 17 00:00:00 2001 From: Tyranja Date: Thu, 22 Jan 2015 15:26:13 +0100 Subject: [PATCH] add Sidekiq for cancelling build : add require sidekiq to the sidekiq.rb update Gemfile.lock bump travis-sidekiqs correct require statement fix another request connect to the database add current user add current user correctly add current user correctly add puts to see were in the condition we are missing invertted comma add comments to the worker I HAVE NO IDEA Revert "I HAVE NO IDEA" This reverts commit 8bd1259bf4ea1b479f9391847a4700b7b15efe57. change the id and source to symbols in the params because siedekiq expects that add more printout setup database connection, metrics and notification correct the test --- Gemfile | 2 +- Gemfile.lock | 43 +++++--------------- lib/travis/api/app/endpoint/builds.rb | 2 +- lib/travis/api/workers/build_cancellation.rb | 8 +++- lib/travis/sidekiq.rb | 13 ++++-- spec/integration/v2/builds_spec.rb | 2 +- 6 files changed, 31 insertions(+), 39 deletions(-) diff --git a/Gemfile b/Gemfile index 7a2f174e..85f6635c 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 's3', github: 'travis-ci/s3' gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-config', '~> 0.1.0' -gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' +gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil gem 'travis-yaml', github: 'travis-ci/travis-yaml' gem 'sinatra' gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil diff --git a/Gemfile.lock b/Gemfile.lock index 3f38a26c..d17be03c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,11 +67,10 @@ GIT GIT remote: git://github.com/travis-ci/travis-sidekiqs.git - revision: cde9741f8e6811fe3929bdd0dd653b87289c5eef - ref: cde9741 + revision: 21a2fee158e25252dd78f5fa31e81b4f6583be23 specs: travis-sidekiqs (0.0.1) - sidekiq (~> 2.5.0) + sidekiq GIT remote: git://github.com/travis-ci/travis-support.git @@ -143,26 +142,13 @@ GEM backports (2.8.2) builder (3.0.4) bunny (0.8.0) - celluloid (0.12.0) - timers (>= 1.0.0) - chunky_png (1.3.3) + celluloid (0.16.0) + timers (~> 4.0.0) coder (0.4.0) coderay (1.1.0) coercible (1.0.0) descendants_tracker (~> 0.0.1) - compass (1.0.1) - chunky_png (~> 1.2) - compass-core (~> 1.0.1) - compass-import-once (~> 1.0.5) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - sass (>= 3.3.13, < 3.5) - compass-core (1.0.1) - multi_json (~> 1.0) - sass (>= 3.3.0, < 3.5) - compass-import-once (1.0.5) - sass (>= 3.2, < 3.5) - connection_pool (0.9.3) + connection_pool (2.1.1) daemons (1.1.9) dalli (2.7.2) data_migrations (0.0.1) @@ -277,16 +263,12 @@ GEM rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.99.2) - sass (3.4.6) - sidekiq (2.5.0) - celluloid (~> 0.12.0) - compass - connection_pool (~> 0.9.2) - multi_json (~> 1) - redis (~> 3) - redis-namespace - sass - sprockets-sass + sidekiq (3.3.0) + celluloid (>= 0.16.0) + connection_pool (>= 2.0.0) + json + redis (>= 3.0.6) + redis-namespace (>= 1.3.1) signature (0.1.7) simple_states (1.0.1) activesupport @@ -310,9 +292,6 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-sass (1.2.0) - sprockets (~> 2.0) - tilt (~> 1.1) thin (1.6.3) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index ed1888d3..ea4bb6b7 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -40,7 +40,7 @@ class Travis::Api::App else #service.run #check syntax of line below - Travis::Sidekiq::BuildCancellation.perform_async(id: params[:id], source: 'api') + Travis::Sidekiq::BuildCancellation.perform_async(id: params[:id], user_id: current_user.id, source: 'api') Metriks.meter("api.request.cancel_build.success").mark status 204 diff --git a/lib/travis/api/workers/build_cancellation.rb b/lib/travis/api/workers/build_cancellation.rb index 019627ca..0fd5ad7c 100644 --- a/lib/travis/api/workers/build_cancellation.rb +++ b/lib/travis/api/workers/build_cancellation.rb @@ -10,8 +10,14 @@ module Travis sidekiq_options queue: :build_cancellations def perform(data) - Travis.service(:cancel_build, data).run + p "#######################" + p data + user = User.find(data['user_id']) + test = { id: data['id'], source: data['source'] } + p test + Travis.service(:cancel_build, user, { id: data['id'], source: data['source'] }).run end + end end end diff --git a/lib/travis/sidekiq.rb b/lib/travis/sidekiq.rb index 3f871713..a144d5da 100644 --- a/lib/travis/sidekiq.rb +++ b/lib/travis/sidekiq.rb @@ -1,7 +1,14 @@ $: << './lib' -require 'travis/core' -require 'travis/app/workers/build_cancellation' +require 'sidekiq' +require 'travis' +require 'travis/api/workers/build_cancellation' +require 'travis/support/amqp' + +Travis::Database.connect +Travis::Amqp.config = Travis.config.amqp +Travis::Metrics.setup +Travis::Notification.setup Sidekiq.configure_server do |config| config.redis = Travis.config.redis.merge(namespace: Travis.config.sidekiq.namespace) -end \ No newline at end of file +end diff --git a/spec/integration/v2/builds_spec.rb b/spec/integration/v2/builds_spec.rb index 8f47aca2..d254229d 100644 --- a/spec/integration/v2/builds_spec.rb +++ b/spec/integration/v2/builds_spec.rb @@ -82,7 +82,7 @@ describe 'Builds' do end it 'cancels the build' do - Travis::Sidekiq::BuildCancellation.expects(:perform_async).with(id: build.id.to_s, source: 'api') + Travis::Sidekiq::BuildCancellation.expects(:perform_async).with( id: build.id.to_s, user_id: user.id, source: 'api') post "/builds/#{build.id}/cancel", {}, headers end