Commit 0c71aac1 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'fp-improve-build-finished-worker-idempotency' into 'master'

Run sync BuildFinishedWorker operations always before

See merge request gitlab-org/gitlab!67117
parents 4fd356ba 99a695e1
...@@ -4,6 +4,11 @@ module EE ...@@ -4,6 +4,11 @@ module EE
module Ci module Ci
module BuildFinishedWorker module BuildFinishedWorker
def process_build(build) def process_build(build)
# Always run `super` first since it contains sync operations.
# Failing to run sync operations would cause the worker to retry
# and enqueueing duplicate jobs.
super
unless ::Feature.enabled?(:cancel_pipelines_prior_to_destroy, build.project, default_enabled: :yaml) unless ::Feature.enabled?(:cancel_pipelines_prior_to_destroy, build.project, default_enabled: :yaml)
::Ci::Minutes::UpdateBuildMinutesService.new(build.project, nil).execute(build) ::Ci::Minutes::UpdateBuildMinutesService.new(build.project, nil).execute(build)
end end
...@@ -15,8 +20,6 @@ module EE ...@@ -15,8 +20,6 @@ module EE
if ::Gitlab.com? && build.has_security_reports? if ::Gitlab.com? && build.has_security_reports?
::Security::TrackSecureScansWorker.perform_async(build.id) ::Security::TrackSecureScansWorker.perform_async(build.id)
end end
super
end end
end end
end end
......
...@@ -56,6 +56,20 @@ RSpec.describe Ci::BuildFinishedWorker do ...@@ -56,6 +56,20 @@ RSpec.describe Ci::BuildFinishedWorker do
subject subject
end end
context 'when exception is raised in `super`' do
before do
allow(::BuildHooksWorker)
.to receive(:perform_async)
.and_raise(ArgumentError)
end
it 'does not enqueue the worker in EE' do
expect { subject }.to raise_error(ArgumentError)
expect(::Security::TrackSecureScansWorker).not_to receive(:perform_async)
end
end
context 'when build does not have a security report' do context 'when build does not have a security report' do
let(:build) { create(:ee_ci_build, :success, runner: ci_runner) } let(:build) { create(:ee_ci_build, :success, runner: ci_runner) }
......
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