Commit bedc9243 authored by Marius Bobin's avatar Marius Bobin

Remove running build entries when calling doom on a build

Changelog: fixed
parent cdeccbce
......@@ -1021,7 +1021,15 @@ module Ci
transaction do
update_columns(status: :failed, failure_reason: :data_integrity_failure)
all_queuing_entries.delete_all
all_runtime_metadata.delete_all
end
Gitlab::AppLogger.info(
message: 'Build doomed',
class: self.class.name,
build_id: id,
pipeline_id: pipeline_id,
project_id: project_id)
end
def degradation_threshold
......@@ -1067,6 +1075,10 @@ module Ci
::Ci::PendingBuild.upsert_from_build!(self)
end
def create_runtime_metadata!
::Ci::RunningBuild.upsert_shared_runner_build!(self)
end
##
# We can have only one queuing entry or running build tracking entry,
# because there is a unique index on `build_id` in each table, but we need
......
......@@ -34,7 +34,7 @@ module Ci
# rubocop: enable CodeReuse/ActiveRecord
def drop_build(type, build, reason)
Gitlab::AppLogger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{build.status}, failure_reason: #{reason})"
log_dropping_message(type, build, reason)
Gitlab::OptimisticLocking.retry_lock(build, 3, name: 'stuck_ci_jobs_worker_drop_build') do |b|
b.drop(reason)
end
......@@ -53,6 +53,16 @@ module Ci
project_id: build.project_id
)
end
def log_dropping_message(type, build, reason)
Gitlab::AppLogger.info(class: self.class.name,
message: "Dropping #{type} build",
build_stuck_type: type,
build_id: build.id,
runner_id: build.runner_id,
build_status: build.status,
build_failure_reason: reason)
end
end
end
end
......@@ -335,6 +335,10 @@ FactoryBot.define do
running
runner factory: :ci_runner
after(:create) do |build|
build.create_runtime_metadata!
end
end
trait :artifacts do
......
......@@ -5427,7 +5427,8 @@ RSpec.describe Ci::Build do
describe '#doom!' do
subject { build.doom! }
let_it_be(:build) { create(:ci_build, :queued) }
let(:traits) { [] }
let(:build) { create(:ci_build, *traits, pipeline: pipeline) }
it 'updates status and failure_reason', :aggregate_failures do
subject
......@@ -5436,6 +5437,18 @@ RSpec.describe Ci::Build do
expect(build.failure_reason).to eq("data_integrity_failure")
end
it 'logs a message' do
expect(Gitlab::AppLogger)
.to receive(:info)
.with(a_hash_including(message: 'Build doomed', class: build.class.name, build_id: build.id))
.and_call_original
subject
end
context 'with queued builds' do
let(:traits) { [:queued] }
it 'drops associated pending build' do
subject
......@@ -5443,6 +5456,17 @@ RSpec.describe Ci::Build do
end
end
context 'with running builds' do
let(:traits) { [:picked] }
it 'drops associated runtime metadata' do
subject
expect(build.reload.runtime_metadata).not_to be_present
end
end
end
it 'does not generate cross DB queries when a record is created via FactoryBot' do
with_cross_database_modification_prevented do
create(:ci_build)
......
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