diff options
Diffstat (limited to 'lib/gitlab/ci/trace.rb')
-rw-r--r-- | lib/gitlab/ci/trace.rb | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb index 5feef77e27e..a52d71225bb 100644 --- a/lib/gitlab/ci/trace.rb +++ b/lib/gitlab/ci/trace.rb @@ -109,31 +109,35 @@ module Gitlab end def archive! + try_obtain_lease do + unsafe_archive! + end + end + + private + + def unsafe_archive! raise ArchiveError, 'Already archived' if trace_artifact raise ArchiveError, 'Job is not finished yet' unless job.complete? - try_obtain_lease do - if job.trace_chunks.any? - Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream| - archive_stream!(stream) - stream.destroy! - end - elsif current_path - File.open(current_path) do |stream| - archive_stream!(stream) - FileUtils.rm(current_path) - end - elsif old_trace - StringIO.new(old_trace, 'rb').tap do |stream| - archive_stream!(stream) - job.erase_old_trace! - end + if job.trace_chunks.any? + Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream| + archive_stream!(stream) + stream.destroy! + end + elsif current_path + File.open(current_path) do |stream| + archive_stream!(stream) + FileUtils.rm(current_path) + end + elsif old_trace + StringIO.new(old_trace, 'rb').tap do |stream| + archive_stream!(stream) + job.erase_old_trace! end end end - private - def archive_stream!(stream) clone_file!(stream, JobArtifactUploader.workhorse_upload_path) do |clone_path| create_build_trace!(job, clone_path) @@ -213,7 +217,7 @@ module Gitlab job.job_artifacts_trace end - # For ExclusiveLeaseGuard concerns + # For ExclusiveLeaseGuard concern def lease_key @lease_key ||= "trace:archive:#{job.id}" end |