diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-06-02 13:08:34 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-06-06 17:49:48 +0900 |
commit | 5a1ee0c391a06a323d960eab6ffb33dfcf2edca7 (patch) | |
tree | 0112d50f35408d4c04c4c6e8b4e473989a08eb97 /lib | |
parent | 2084e7ab9aad92d4a8196af01b9b8e02ffacb0a4 (diff) | |
download | gitlab-ce-5a1ee0c391a06a323d960eab6ffb33dfcf2edca7.tar.gz |
Fix the query to select stale live traces
Diffstat (limited to 'lib')
-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 |