2021-07-13 11:08:38 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class BuildFinishedWorker # rubocop:disable Scalability/IdempotentWorker
|
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-07-21 08:09:35 -04:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-07-13 11:08:38 -04:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
include PipelineQueue
|
|
|
|
|
|
|
|
queue_namespace :pipeline_processing
|
|
|
|
urgency :high
|
|
|
|
worker_resource_boundary :cpu
|
|
|
|
|
|
|
|
ARCHIVE_TRACES_IN = 2.minutes.freeze
|
|
|
|
|
|
|
|
def perform(build_id)
|
2021-11-10 10:13:21 -05:00
|
|
|
return unless build = Ci::Build.find_by_id(build_id)
|
2021-10-11 05:09:08 -04:00
|
|
|
return unless build.project
|
|
|
|
return if build.project.pending_delete?
|
|
|
|
|
|
|
|
process_build(build)
|
2021-07-13 11:08:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Processes a single CI build that has finished.
|
|
|
|
#
|
|
|
|
# This logic resides in a separate method so that EE can extend it more
|
|
|
|
# easily.
|
|
|
|
#
|
|
|
|
# @param [Ci::Build] build The build to process.
|
|
|
|
def process_build(build)
|
|
|
|
# We execute these in sync to reduce IO.
|
|
|
|
build.update_coverage
|
|
|
|
Ci::BuildReportResultService.new.execute(build)
|
|
|
|
|
|
|
|
# We execute these async as these are independent operations.
|
|
|
|
BuildHooksWorker.perform_async(build.id)
|
|
|
|
ChatNotificationWorker.perform_async(build.id) if build.pipeline.chat?
|
2022-02-24 07:12:57 -05:00
|
|
|
build.track_deployment_usage
|
2021-07-13 11:08:38 -04:00
|
|
|
|
2022-01-19 10:14:05 -05:00
|
|
|
if build.failed? && !build.auto_retry_expected?
|
2021-07-13 11:08:38 -04:00
|
|
|
::Ci::MergeRequests::AddTodoWhenBuildFailsWorker.perform_async(build.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# We want to delay sending a build trace to object storage operation to
|
|
|
|
# validate that this fixes a race condition between this and flushing live
|
|
|
|
# trace chunks and chunks being removed after consolidation and putting
|
|
|
|
# them into object storage archive.
|
|
|
|
#
|
|
|
|
# TODO This is temporary fix we should improve later, after we validate
|
|
|
|
# that this is indeed the culprit.
|
|
|
|
#
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/-/issues/267112 for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
archive_trace_worker_class(build).perform_in(ARCHIVE_TRACES_IN, build.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def archive_trace_worker_class(build)
|
2022-05-06 11:09:03 -04:00
|
|
|
if Feature.enabled?(:ci_build_finished_worker_namespace_changed, build.project)
|
2021-07-13 11:08:38 -04:00
|
|
|
Ci::ArchiveTraceWorker
|
|
|
|
else
|
|
|
|
::ArchiveTraceWorker
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Ci::BuildFinishedWorker.prepend_mod_with('Ci::BuildFinishedWorker')
|