Commit dee08e12 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'noop-build-finished-for-deleted-projects' into 'master'

No-op BuildFinishedWorker for deleted and pending_delete projects

See merge request gitlab-org/gitlab!71962
parents d2e17c0c 1c4b9e9d
......@@ -15,13 +15,13 @@ module Ci
ARCHIVE_TRACES_IN = 2.minutes.freeze
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
process_build(build)
end
return unless build = Ci::Build.find_by(id: build_id) # rubocop: disable CodeReuse/ActiveRecord
return unless build.project
return if build.project.pending_delete?
process_build(build)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -3,7 +3,9 @@
require 'spec_helper'
RSpec.describe BuildFinishedWorker do
subject { described_class.new.perform(build.id) }
let(:worker) { described_class.new }
subject { worker.perform(build.id) }
describe '#perform' do
context 'when build exists' do
......@@ -63,6 +65,30 @@ RSpec.describe BuildFinishedWorker do
subject
end
end
context 'when project is deleted' do
before do
allow(build).to receive(:project).and_return(nil)
end
it 'does no processing' do
expect(worker).not_to receive(:process_build)
subject
end
end
context 'when project is pending_delete' do
before do
build.project.update_attribute(:pending_delete, true)
end
it 'does no processing' do
expect(worker).not_to receive(:process_build)
subject
end
end
end
context 'when build does not exist' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment