summaryrefslogtreecommitdiff
path: root/app/workers/build_finished_worker.rb
blob: 3f99b30fdf7d244f4aa2b0f996f32e75d8d1f09b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

class BuildFinishedWorker # rubocop:disable Scalability/IdempotentWorker
  include ApplicationWorker
  include PipelineQueue

  queue_namespace :pipeline_processing
  urgency :high
  worker_resource_boundary :cpu

  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
  end
  # rubocop: enable CodeReuse/ActiveRecord

  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.parse_trace_sections!
    build.update_coverage
    Ci::BuildReportResultService.new.execute(build)

    # We execute these async as these are independent operations.
    BuildHooksWorker.perform_async(build.id)
    ExpirePipelineCacheWorker.perform_async(build.pipeline_id)
    ChatNotificationWorker.perform_async(build.id) if build.pipeline.chat?

    ##
    # 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.
    #
    ArchiveTraceWorker.perform_in(ARCHIVE_TRACES_IN, build.id)
  end
end

BuildFinishedWorker.prepend_if_ee('EE::BuildFinishedWorker')