summaryrefslogtreecommitdiff
path: root/app/models/ci/build.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-06-14 16:23:16 +0200
committerDouwe Maan <douwe@selenight.nl>2016-06-14 16:23:16 +0200
commit9413d1c2e9c4cebe32921f6e403cf496e3ec8c58 (patch)
treeac829f9a9bb88f4e6ca36ef071005ea5c2088336 /app/models/ci/build.rb
parent515205d3c1c6655302ed0ae44cc5954dead7ae79 (diff)
parentd4cd6dcaa024f8eca9089e67fb9b97022696d3e0 (diff)
downloadgitlab-ce-9413d1c2e9c4cebe32921f6e403cf496e3ec8c58.tar.gz
Merge branch 'master' into 13948-access-request-to-projects-and-groups
# Conflicts: # app/views/layouts/nav/_project.html.haml
Diffstat (limited to 'app/models/ci/build.rb')
-rw-r--r--app/models/ci/build.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 6a64ca451f7..89a1f8b3f57 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -11,6 +11,8 @@ module Ci
scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) }
+ scope :with_artifacts, ->() { where.not(artifacts_file: nil) }
+ scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
mount_uploader :artifacts_file, ArtifactUploader
mount_uploader :artifacts_metadata, ArtifactUploader
@@ -317,7 +319,7 @@ module Ci
end
def artifacts?
- artifacts_file.exists?
+ !artifacts_expired? && artifacts_file.exists?
end
def artifacts_metadata?
@@ -328,11 +330,15 @@ module Ci
Gitlab::Ci::Build::Artifacts::Metadata.new(artifacts_metadata.path, path, **options).to_entry
end
+ def erase_artifacts!
+ remove_artifacts_file!
+ remove_artifacts_metadata!
+ end
+
def erase(opts = {})
return false unless erasable?
- remove_artifacts_file!
- remove_artifacts_metadata!
+ erase_artifacts!
erase_trace!
update_erased!(opts[:erased_by])
end
@@ -345,6 +351,25 @@ module Ci
!self.erased_at.nil?
end
+ def artifacts_expired?
+ artifacts_expire_at && artifacts_expire_at < Time.now
+ end
+
+ def artifacts_expire_in
+ artifacts_expire_at - Time.now if artifacts_expire_at
+ end
+
+ def artifacts_expire_in=(value)
+ self.artifacts_expire_at =
+ if value
+ Time.now + ChronicDuration.parse(value)
+ end
+ end
+
+ def keep_artifacts!
+ self.update(artifacts_expire_at: nil)
+ end
+
private
def erase_trace!
@@ -352,7 +377,7 @@ module Ci
end
def update_erased!(user = nil)
- self.update(erased_by: user, erased_at: Time.now)
+ self.update(erased_by: user, erased_at: Time.now, artifacts_expire_at: nil)
end
def yaml_variables