Commit 7357021e authored by Thong Kuah's avatar Thong Kuah

Move LB sticking for CI build to Core

parent 064e9d3c
......@@ -214,6 +214,8 @@ module Ci
before_save :ensure_token
before_destroy { unscoped_project }
after_save :stick_build_if_status_changed
after_create unless: :importing? do |build|
run_after_commit { BuildHooksWorker.perform_async(build.id) }
end
......@@ -1082,6 +1084,13 @@ module Ci
private
def stick_build_if_status_changed
return unless saved_change_to_status?
return unless running?
::Gitlab::Database::LoadBalancing::Sticking.stick(:build, id)
end
def status_commit_hooks
@status_commit_hooks ||= []
end
......
......@@ -31,7 +31,6 @@ module EE
has_many :security_scans, class_name: 'Security::Scan'
after_save :stick_build_if_status_changed
after_commit :track_ci_secrets_management_usage, on: :create
delegate :service_specification, to: :runner_session, allow_nil: true
......@@ -62,13 +61,6 @@ module EE
project.shared_runners_minutes_limit_enabled? && runner&.minutes_cost_factor(project.visibility_level)&.positive?
end
def stick_build_if_status_changed
return unless saved_change_to_status?
return unless running?
::Gitlab::Database::LoadBalancing::Sticking.stick(:build, id)
end
def log_geo_deleted_event
# It is not needed to generate a Geo deleted event
# since Legacy Artifacts are migrated to multi-build artifacts
......
......@@ -107,20 +107,6 @@ RSpec.describe Ci::Build do
end
end
describe '#stick_build_if_status_changed' do
it 'sticks the build if the status changed' do
job = create(:ci_build, :pending)
allow(Gitlab::Database::LoadBalancing).to receive(:enable?)
.and_return(true)
expect(Gitlab::Database::LoadBalancing::Sticking).to receive(:stick)
.with(:build, job.id)
job.update!(status: :running)
end
end
describe '#variables' do
subject { job.variables }
......
......@@ -320,6 +320,20 @@ RSpec.describe Ci::Build do
end
end
describe '#stick_build_if_status_changed' do
it 'sticks the build if the status changed' do
job = create(:ci_build, :pending)
allow(Gitlab::Database::LoadBalancing).to receive(:enable?)
.and_return(true)
expect(Gitlab::Database::LoadBalancing::Sticking).to receive(:stick)
.with(:build, job.id)
job.update!(status: :running)
end
end
describe '#enqueue' do
let(:build) { create(:ci_build, :created) }
......
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