Commit 8deb1c70 authored by Sean Arnold's avatar Sean Arnold

Retry archive if left in incomplete state

Changelog: changed
parent fa457780
......@@ -194,7 +194,7 @@ module Gitlab
if trace_artifact
unsafe_trace_cleanup!
raise AlreadyArchivedError, 'Could not archive again'
raise AlreadyArchivedError, 'Could not archive again' if already_archived?
end
if job.trace_chunks.any?
......@@ -215,14 +215,20 @@ module Gitlab
end
end
def already_archived?
# TODO check checksum to ensure archive completed successfully
# See https://gitlab.com/gitlab-org/gitlab/-/issues/259619
trace_artifact&.archived_trace_exists?
end
def unsafe_trace_cleanup!
return unless trace_artifact
if trace_artifact.archived_trace_exists?
if already_archived?
# An archive already exists, so make sure to remove the trace chunks
erase_trace_chunks!
else
# An archive already exists, but its associated file does not, so remove it
# An archive already exists, but its associated file is not complete, so remove it
trace_artifact.destroy!
end
end
......
......@@ -28,7 +28,7 @@ RSpec.describe Ci::ArchiveTraceService, '#execute' do
context 'when live trace chunks still exist' do
before do
create(:ci_build_trace_chunk, build: job)
create(:ci_build_trace_chunk, build: job, chunk_index: 0)
end
it 'removes the trace chunks' do
......@@ -40,8 +40,14 @@ RSpec.describe Ci::ArchiveTraceService, '#execute' do
job.job_artifacts_trace.file.remove!
end
it 'removes the trace artifact' do
expect { subject }.to change { job.reload.job_artifacts_trace }.to(nil)
it 'removes the trace artifact and builds a new one' do
existing_trace = job.job_artifacts_trace
expect(existing_trace).to receive(:destroy!).and_call_original
subject
expect(job.reload.job_artifacts_trace).to be_present
expect(job.reload.job_artifacts_trace.file.file).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