diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 923c712a..b23b8258 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -23,11 +23,6 @@ class Travis::Api::App Metriks.meter("api.request.cancel_build").mark service = Travis::Enqueue::Services::CancelModel.new(current_user, { build_id: params[:id] }) - repository_owner = service.target.repository.owner - - if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner) - service = self.service(:cancel_build, params.merge(source: 'api')) - end if !service.authorized? json = { error: { @@ -48,11 +43,8 @@ class Travis::Api::App respond_with json else payload = { id: params[:id], user_id: current_user.id, source: 'api' } - if service.respond_to?(:push) - service.push("build:cancel", payload) - else - Travis::Sidekiq::BuildCancellation.perform_async(payload) - end + + service.push("build:cancel", payload) Metriks.meter("api.request.cancel_build.success").mark status 204 @@ -62,24 +54,15 @@ class Travis::Api::App post '/:id/restart' do Metriks.meter("api.request.restart_build").mark service = Travis::Enqueue::Services::RestartModel.new(current_user, build_id: params[:id]) - repository_owner = service.target.repository.owner - - if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner) - service = self.service(:reset_model, build_id: params[:id]) - end result = if !service.accept? status 400 false - elsif service.respond_to?(:push) + else payload = { id: params[:id], user_id: current_user.id } service.push("build:restart", payload) status 202 true - else - Travis::Sidekiq::BuildRestart.perform_async(id: params[:id], user_id: current_user.id) - status 202 - true end respond_with(result: result, flash: service.messages) diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index aafef56c..4a217625 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -30,10 +30,6 @@ class Travis::Api::App Metriks.meter("api.request.cancel_job").mark service = Travis::Enqueue::Services::CancelModel.new(current_user, { job_id: params[:id] }) - repository_owner = service.target.repository.owner - if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner) - service = self.service(:cancel_job, params.merge(source: 'api')) - end if !service.authorized? json = { error: { @@ -54,11 +50,7 @@ class Travis::Api::App respond_with json else payload = { id: params[:id], user_id: current_user.id, source: 'api' } - if service.respond_to?(:push) - service.push("job:cancel", payload) - else - Travis::Sidekiq::JobCancellation.perform_async(payload) - end + service.push("job:cancel", payload) Metriks.meter("api.request.cancel_job.success").mark status 204 @@ -69,23 +61,15 @@ class Travis::Api::App Metriks.meter("api.request.restart_job").mark service = Travis::Enqueue::Services::RestartModel.new(current_user, { job_id: params[:id] }) - repository_owner = service.target.repository.owner - if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner) - service = self.service(:reset_model, job_id: params[:id]) - end result = if !service.accept? status 400 false - elsif service.respond_to?(:push) + else payload = {id: params[:id], user_id: current_user.id} service.push("job:restart", payload) status 202 true - else - Travis::Sidekiq::JobRestart.perform_async(id: params[:id], user_id: current_user.id) - status 202 - result = true end respond_with(result: result, flash: service.messages) diff --git a/spec/integration/v2/builds_spec.rb b/spec/integration/v2/builds_spec.rb index 5670c46a..de6eab2d 100644 --- a/spec/integration/v2/builds_spec.rb +++ b/spec/integration/v2/builds_spec.rb @@ -97,20 +97,6 @@ describe 'Builds', set_app: true do build.update_attribute(:state, 'created') end - context 'from the Core' do - before { Travis::Sidekiq::BuildCancellation.stubs(:perform_async) } - - it 'cancels the build' do - 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 - - it 'responds with 204' do - response = post "/builds/#{build.id}/cancel", {}, headers - response.status.should == 204 - end - end - context 'and enqueues cancel event for the Hub' do before { Travis::Features.activate_owner(:enqueue_to_hub, repo.owner) } @@ -173,23 +159,6 @@ describe 'Builds', set_app: true do body.should == {"result"=>true, "flash"=>[{"notice"=>"The build was successfully restarted."}]} end end - - describe 'Restart from the Core' do - before { Travis::Sidekiq::BuildRestart.stubs(:perform_async) } - - it 'restarts the build' do - Travis::Sidekiq::BuildRestart.expects(:perform_async).with(id: build.id.to_s, user_id: user.id) - response = post "/builds/#{build.id}/restart", {}, headers - response.status.should == 202 - end - - it 'sends the correct response body' do - Travis::Sidekiq::BuildRestart.expects(:perform_async).with(id: build.id.to_s, user_id: user.id) - response = post "/builds/#{build.id}/restart", {}, headers - body = JSON.parse(response.body) - body.should == {"result"=>true, "flash"=>[{"notice"=>"The build was successfully restarted."}]} - end - end end end end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index f618088e..1f5eecd6 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -262,16 +262,6 @@ describe 'Jobs', set_app: true do job.update_attribute(:state, 'created') end - it 'cancels the job' do - Travis::Sidekiq::JobCancellation.expects(:perform_async).with( id: job.id.to_s, user_id: user.id, source: 'api') - post "/jobs/#{job.id}/cancel", {}, headers - end - - it 'responds with 204' do - response = post "/jobs/#{job.id}/cancel", {}, headers - response.status.should == 204 - end - context 'and enqueues cancel event for the Hub' do before { Travis::Features.activate_owner(:enqueue_to_hub, job.repository.owner) } @@ -319,22 +309,6 @@ describe 'Jobs', set_app: true do context 'when job passed' do before { job.update_attribute(:state, 'passed') } - context 'Restart from travis-core' do - before { Travis::Sidekiq::JobCancellation.stubs(:perform_async) } - - it 'restarts the job' do - Travis::Sidekiq::JobRestart.expects(:perform_async).with(id: job.id.to_s, user_id: user.id) - response = post "/jobs/#{job.id}/restart", {}, headers - response.status.should == 202 - end - it 'sends the correct response body' do - Travis::Sidekiq::JobRestart.expects(:perform_async).with(id: job.id.to_s, user_id: user.id) - response = post "/jobs/#{job.id}/restart", {}, headers - body = JSON.parse(response.body) - body.should == {"result"=>true, "flash"=>[{"notice"=>"The job was successfully restarted."}]} - end - end - context 'Enqueues restart event for the Hub' do before { Travis::Features.activate_owner(:enqueue_to_hub, job.repository.owner) }