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,10 +5437,33 @@ RSpec.describe Ci::Build do
expect(build.failure_reason).to eq("data_integrity_failure")
end
it 'drops associated pending build' do
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
expect(build.reload.queuing_entry).not_to be_present
end
end
expect(build.reload.queuing_entry).not_to be_present
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
......
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