refactor buildcancellation worker
This commit is contained in:
parent
39bd25cc3b
commit
9b4d121956
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ config/travis.yml
|
||||||
log/
|
log/
|
||||||
vendor
|
vendor
|
||||||
config/skylight.yml
|
config/skylight.yml
|
||||||
|
.coverage
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require 'travis/api/app'
|
require 'travis/api/app'
|
||||||
|
require 'travis/api/workers/build_cancellation'
|
||||||
|
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
class Endpoint
|
class Endpoint
|
||||||
|
@ -39,7 +40,7 @@ class Travis::Api::App
|
||||||
else
|
else
|
||||||
#service.run
|
#service.run
|
||||||
#check syntax of line below
|
#check syntax of line below
|
||||||
Travis::Sidekiq::BuildCancellation.perform_async(params.merge(source: 'api'))
|
Travis::Sidekiq::BuildCancellation.perform_async(id: params[:id], source: 'api')
|
||||||
|
|
||||||
Metriks.meter("api.request.cancel_build.success").mark
|
Metriks.meter("api.request.cancel_build.success").mark
|
||||||
status 204
|
status 204
|
||||||
|
|
|
@ -7,22 +7,10 @@ module Travis
|
||||||
class ProcessingError < StandardError; end
|
class ProcessingError < StandardError; end
|
||||||
|
|
||||||
include ::Sidekiq::Worker
|
include ::Sidekiq::Worker
|
||||||
# do we need to name the queue here? we didn't do this in Admin. We passed this info in the procfile
|
sidekiq_options queue: :build_cancellations
|
||||||
sidekiq_options queue: build_cancellations
|
|
||||||
|
|
||||||
attr_accessor :data
|
|
||||||
|
|
||||||
def perform(data)
|
def perform(data)
|
||||||
@data = data
|
Travis.service(:cancel_build, data).run
|
||||||
if payload
|
|
||||||
service.run
|
|
||||||
else
|
|
||||||
Travis.logger.warn("The #{type} payload was empty and could not be processed")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def service
|
|
||||||
@service ||= Travis.service(:cancel_build, data)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,17 +75,20 @@ describe 'Builds' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when build can be canceled' do
|
context 'when build can be canceled' do
|
||||||
it 'cancels the build and responds with 204' do
|
before do
|
||||||
|
Travis::Sidekiq::BuildCancellation.stubs(:perform_async)
|
||||||
build.matrix.each { |j| j.update_attribute(:state, 'created') }
|
build.matrix.each { |j| j.update_attribute(:state, 'created') }
|
||||||
build.update_attribute(:state, 'created')
|
build.update_attribute(:state, 'created')
|
||||||
|
end
|
||||||
|
|
||||||
response = nil
|
it 'cancels the build' do
|
||||||
expect {
|
Travis::Sidekiq::BuildCancellation.expects(:perform_async).with(id: build.id.to_s, source: 'api')
|
||||||
|
post "/builds/#{build.id}/cancel", {}, headers
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'responds with 204' do
|
||||||
response = post "/builds/#{build.id}/cancel", {}, headers
|
response = post "/builds/#{build.id}/cancel", {}, headers
|
||||||
}.to change { build.reload.state }
|
|
||||||
response.status.should == 204
|
response.status.should == 204
|
||||||
|
|
||||||
build.state.should == 'canceled'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user