diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-07-06 15:19:01 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-07-06 15:19:01 +0900 |
commit | 1667b65c1ea43882da1611c4454618d8a1eca8cc (patch) | |
tree | 733f11290fdb8c13e85b642a438f40b4fae1e045 | |
parent | 9c9bb49b0fd3dfa4d25f2958185809f8bfae6f3d (diff) | |
download | gitlab-ce-1667b65c1ea43882da1611c4454618d8a1eca8cc.tar.gz |
Use AlreadyArchivedError if it's the case
-rw-r--r-- | app/workers/ci/archive_traces_cron_worker.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/trace.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 1 | ||||
-rw-r--r-- | spec/support/shared_examples/ci_trace_shared_examples.rb | 6 |
4 files changed, 8 insertions, 8 deletions
diff --git a/app/workers/ci/archive_traces_cron_worker.rb b/app/workers/ci/archive_traces_cron_worker.rb index eca1c681b23..7d4e9660a4e 100644 --- a/app/workers/ci/archive_traces_cron_worker.rb +++ b/app/workers/ci/archive_traces_cron_worker.rb @@ -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 diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb index 6a65cec5f03..6be5a59dd38 100644 --- a/lib/gitlab/ci/trace.rb +++ b/lib/gitlab/ci/trace.rb @@ -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? diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index e7639599874..d57993ab454 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -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' diff --git a/spec/support/shared_examples/ci_trace_shared_examples.rb b/spec/support/shared_examples/ci_trace_shared_examples.rb index cf2d63c8bc0..8a91e05b2d0 100644 --- a/spec/support/shared_examples/ci_trace_shared_examples.rb +++ b/spec/support/shared_examples/ci_trace_shared_examples.rb @@ -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 |