Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-05-31 10:11:53 +0300
committerShinya Maeda <shinya@gitlab.com>2018-06-06 11:49:48 +0300
commitded38d5f48721b772fe23f3b7856c385f42b4fff (patch)
tree7f8ad9d1594da571f3c93c244991621b7505f3a5 /lib
parentad12c58fadeadb12014aa245e556fa0d4209d6d6 (diff)
Add exclusive relase for trace arhive
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/trace.rb44
1 files changed, 30 insertions, 14 deletions
diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb
index fe15fabc2e8..30f6c624be4 100644
--- a/lib/gitlab/ci/trace.rb
+++ b/lib/gitlab/ci/trace.rb
@@ -1,6 +1,10 @@
module Gitlab
module Ci
class Trace
+ include ExclusiveLeaseGuard
+
+ LEASE_TIMEOUT = 1.hour
+
ArchiveError = Class.new(StandardError)
attr_reader :job
@@ -108,20 +112,22 @@ module Gitlab
raise ArchiveError, 'Already archived' if trace_artifact
raise ArchiveError, 'Job is not finished yet' unless job.complete?
- 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!
+ 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
end
end
end
@@ -206,6 +212,16 @@ module Gitlab
def trace_artifact
job.job_artifacts_trace
end
+
+ # For ExclusiveLeaseGuard concerns
+ def lease_key
+ @lease_key ||= self.class.name.underscore + ":archive:#{job.id}"
+ end
+
+ # For ExclusiveLeaseGuard concern
+ def lease_timeout
+ LEASE_TIMEOUT
+ end
end
end
end