Commit c4bde1c3 authored by Yorick Peterse's avatar Yorick Peterse

Refactor BuildFinishedWorker for EE

This simply moves the logic from the "perform" method into a separate
"process_build" method, allowing EE to more easily extend this
behaviour.
parent afb5b9d2
...@@ -9,18 +9,28 @@ class BuildFinishedWorker ...@@ -9,18 +9,28 @@ class BuildFinishedWorker
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by(id: build_id).try do |build|
UpdateBuildMinutesService.new(build.project, nil).execute(build) process_build(build)
# We execute that in sync as this access the files in order to access local file, and reduce IO
BuildTraceSectionsWorker.new.perform(build.id)
BuildCoverageWorker.new.perform(build.id)
# We execute that async as this are two independent operations that can be executed after TraceSections and Coverage
BuildHooksWorker.perform_async(build.id)
ArchiveTraceWorker.perform_async(build.id)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord # 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.
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)
end
end end
BuildFinishedWorker.prepend(EE::BuildFinishedWorker) BuildFinishedWorker.prepend(EE::BuildFinishedWorker)
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
module EE module EE
module BuildFinishedWorker module BuildFinishedWorker
# rubocop: disable CodeReuse/ActiveRecord def process_build(build)
def perform(build_id) UpdateBuildMinutesService.new(build.project, nil).execute(build)
super super
::Ci::Build.find_by(id: build_id).try do |build| ChatNotificationWorker.perform_async(build.id) if build.pipeline.chat?
ChatNotificationWorker.perform_async(build_id) if build.pipeline.chat?
end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
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