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/
|
||||
vendor
|
||||
config/skylight.yml
|
||||
.coverage
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'travis/api/app'
|
||||
require 'travis/api/workers/build_cancellation'
|
||||
|
||||
class Travis::Api::App
|
||||
class Endpoint
|
||||
|
@ -39,7 +40,7 @@ class Travis::Api::App
|
|||
else
|
||||
#service.run
|
||||
#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
|
||||
status 204
|
||||
|
|
|
@ -7,23 +7,11 @@ module Travis
|
|||
class ProcessingError < StandardError; end
|
||||
|
||||
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
|
||||
|
||||
attr_accessor :data
|
||||
sidekiq_options queue: :build_cancellations
|
||||
|
||||
def perform(data)
|
||||
@data = data
|
||||
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)
|
||||
Travis.service(:cancel_build, data).run
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,17 +75,20 @@ describe 'Builds' do
|
|||
end
|
||||
|
||||
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.update_attribute(:state, 'created')
|
||||
end
|
||||
|
||||
response = nil
|
||||
expect {
|
||||
response = post "/builds/#{build.id}/cancel", {}, headers
|
||||
}.to change { build.reload.state }
|
||||
it 'cancels the build' do
|
||||
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.status.should == 204
|
||||
|
||||
build.state.should == 'canceled'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user