Use AlreadyArchivedError if it's the case

This commit is contained in:
Shinya Maeda 2018-07-06 15:19:01 +09:00
parent 9c9bb49b0f
commit 1667b65c1e
4 changed files with 8 additions and 8 deletions

View file

@ -12,9 +12,8 @@ module Ci
Ci::Build.finished.with_live_trace.find_each(batch_size: 100) do |build|
begin
build.trace.archive!
rescue ::Gitlab::Ci::Trace::AlreadyArchivedError
rescue => e
next if e.message.include?('Already archived')
failed_archive_counter.increment
Rails.logger.error "Failed to archive stale live trace. id: #{build.id} message: #{e.message}"
end

View file

@ -6,7 +6,7 @@ module Gitlab
LEASE_TIMEOUT = 1.hour
ArchiveError = Class.new(StandardError)
WriteError = Class.new(StandardError)
AlreadyArchivedError = Class.new(StandardError)
attr_reader :job
@ -83,7 +83,7 @@ module Gitlab
def write(mode)
stream = Gitlab::Ci::Trace::Stream.new do
if trace_artifact
raise WriteError, 'Already archived'
raise AlreadyArchivedError, 'Could not write to the archived trace'
elsif current_path
File.open(current_path, mode)
elsif Feature.enabled?('ci_enable_live_trace')
@ -120,7 +120,7 @@ module Gitlab
private
def unsafe_archive!
raise ArchiveError, 'Already archived' if trace_artifact
raise AlreadyArchivedError, 'Could not archive again' if trace_artifact
raise ArchiveError, 'Job is not finished yet' unless job.complete?
if job.trace_chunks.any?

View file

@ -851,6 +851,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
it 'does not update job status and job trace' do
update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
job.reload
expect(response).to have_gitlab_http_status(403)
expect(response.header['Job-Status']).to eq 'failed'
expect(job.trace.raw).to eq 'Job failed'

View file

@ -155,7 +155,7 @@ shared_examples_for 'common trace features' do
end
it 'raises an error' do
expect { subject }.to raise_error('Already archived')
expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError)
end
end
end
@ -596,7 +596,7 @@ shared_examples_for 'trace with disabled live trace feature' do
it 'does not archive' do
expect_any_instance_of(described_class).not_to receive(:archive_stream!)
expect { subject }.to raise_error('Already archived')
expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError)
expect(build.job_artifacts_trace.file.exists?).to be_truthy
end
end
@ -783,7 +783,7 @@ shared_examples_for 'trace with enabled live trace feature' do
it 'does not archive' do
expect_any_instance_of(described_class).not_to receive(:archive_stream!)
expect { subject }.to raise_error('Already archived')
expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError)
expect(build.job_artifacts_trace.file.exists?).to be_truthy
end
end