Commit 1667b65c authored by Shinya Maeda's avatar Shinya Maeda

Use AlreadyArchivedError if it's the case

parent 9c9bb49b
...@@ -12,9 +12,8 @@ module Ci ...@@ -12,9 +12,8 @@ module Ci
Ci::Build.finished.with_live_trace.find_each(batch_size: 100) do |build| Ci::Build.finished.with_live_trace.find_each(batch_size: 100) do |build|
begin begin
build.trace.archive! build.trace.archive!
rescue ::Gitlab::Ci::Trace::AlreadyArchivedError
rescue => e rescue => e
next if e.message.include?('Already archived')
failed_archive_counter.increment failed_archive_counter.increment
Rails.logger.error "Failed to archive stale live trace. id: #{build.id} message: #{e.message}" Rails.logger.error "Failed to archive stale live trace. id: #{build.id} message: #{e.message}"
end end
......
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
LEASE_TIMEOUT = 1.hour LEASE_TIMEOUT = 1.hour
ArchiveError = Class.new(StandardError) ArchiveError = Class.new(StandardError)
WriteError = Class.new(StandardError) AlreadyArchivedError = Class.new(StandardError)
attr_reader :job attr_reader :job
...@@ -83,7 +83,7 @@ module Gitlab ...@@ -83,7 +83,7 @@ module Gitlab
def write(mode) def write(mode)
stream = Gitlab::Ci::Trace::Stream.new do stream = Gitlab::Ci::Trace::Stream.new do
if trace_artifact if trace_artifact
raise WriteError, 'Already archived' raise AlreadyArchivedError, 'Could not write to the archived trace'
elsif current_path elsif current_path
File.open(current_path, mode) File.open(current_path, mode)
elsif Feature.enabled?('ci_enable_live_trace') elsif Feature.enabled?('ci_enable_live_trace')
...@@ -120,7 +120,7 @@ module Gitlab ...@@ -120,7 +120,7 @@ module Gitlab
private private
def unsafe_archive! 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? raise ArchiveError, 'Job is not finished yet' unless job.complete?
if job.trace_chunks.any? if job.trace_chunks.any?
......
...@@ -851,6 +851,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -851,6 +851,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
it 'does not update job status and job trace' do it 'does not update job status and job trace' do
update_job(state: 'success', trace: 'BUILD TRACE UPDATED') update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
job.reload
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(403)
expect(response.header['Job-Status']).to eq 'failed' expect(response.header['Job-Status']).to eq 'failed'
expect(job.trace.raw).to eq 'Job failed' expect(job.trace.raw).to eq 'Job failed'
......
...@@ -155,7 +155,7 @@ shared_examples_for 'common trace features' do ...@@ -155,7 +155,7 @@ shared_examples_for 'common trace features' do
end end
it 'raises an error' do it 'raises an error' do
expect { subject }.to raise_error('Already archived') expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError)
end end
end end
end end
...@@ -596,7 +596,7 @@ shared_examples_for 'trace with disabled live trace feature' do ...@@ -596,7 +596,7 @@ shared_examples_for 'trace with disabled live trace feature' do
it 'does not archive' do it 'does not archive' do
expect_any_instance_of(described_class).not_to receive(:archive_stream!) 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 expect(build.job_artifacts_trace.file.exists?).to be_truthy
end end
end end
...@@ -783,7 +783,7 @@ shared_examples_for 'trace with enabled live trace feature' do ...@@ -783,7 +783,7 @@ shared_examples_for 'trace with enabled live trace feature' do
it 'does not archive' do it 'does not archive' do
expect_any_instance_of(described_class).not_to receive(:archive_stream!) 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 expect(build.job_artifacts_trace.file.exists?).to be_truthy
end 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