build_finished_worker.rb 1.16 KB
Newer Older
1 2
# frozen_string_literal: true

3
class BuildFinishedWorker
4
  include ApplicationWorker
5 6
  include PipelineQueue

7
  queue_namespace :pipeline_processing
8 9
  latency_sensitive_worker!
  worker_resource_boundary :cpu
10

11
  # rubocop: disable CodeReuse/ActiveRecord
12 13
  def perform(build_id)
    Ci::Build.find_by(id: build_id).try do |build|
14
      process_build(build)
15 16
    end
  end
17
  # rubocop: enable CodeReuse/ActiveRecord
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

  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.
    BuildTraceSectionsWorker.new.perform(build.id)
    BuildCoverageWorker.new.perform(build.id)

    # We execute these async as these are independent operations.
    BuildHooksWorker.perform_async(build.id)
    ArchiveTraceWorker.perform_async(build.id)
35
    ExpirePipelineCacheWorker.perform_async(build.pipeline_id) if build.pipeline.cacheable?
36
    ChatNotificationWorker.perform_async(build.id) if build.pipeline.chat?
37
  end
38
end
39

40
BuildFinishedWorker.prepend_if_ee('EE::BuildFinishedWorker')