diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-08 17:18:54 +0200 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-06-13 11:03:30 +0100 |
commit | ffe8dbde9b2aec2425e7859aeed5ad1642c53938 (patch) | |
tree | b6c756b788cbe8a64f4c7d2a4889c3339af93ba6 /app | |
parent | aea4041ce96f18afea70da15af3cbe1be4fa1f94 (diff) | |
download | gitlab-ce-ffe8dbde9b2aec2425e7859aeed5ad1642c53938.tar.gz |
Move keep to ArtifactsController
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/artifacts_controller.rb | 5 | ||||
-rw-r--r-- | app/models/ci/build.rb | 8 | ||||
-rw-r--r-- | app/views/projects/builds/_sidebar.html.haml | 19 | ||||
-rw-r--r-- | app/workers/expire_build_artifacts_worker.rb (renamed from app/workers/expire_build_artifacts.rb) | 3 |
4 files changed, 21 insertions, 14 deletions
diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index 832d7deb57d..028e1f77119 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -34,6 +34,11 @@ class Projects::ArtifactsController < Projects::ApplicationController end end + def keep + build.keep_artifacts! + redirect_to namespace_project_build_path(project.namespace, project, build) + end + private def build diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 74084b650cf..5eb9fe5f1f5 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -12,7 +12,7 @@ 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_artifacts_expired, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } + scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader @@ -352,10 +352,10 @@ module Ci end def artifacts_expired? - self.artifacts_expire_at < Time.now && !artifacts? + !artifacts? && artifacts_expire_at && artifacts_expire_at < Time.now end - def keep_artifacts + def keep_artifacts! self.update(artifacts_expire_at: nil) end @@ -366,7 +366,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 diff --git a/app/views/projects/builds/_sidebar.html.haml b/app/views/projects/builds/_sidebar.html.haml index d1a0da29ef7..e1fdd7019ff 100644 --- a/app/views/projects/builds/_sidebar.html.haml +++ b/app/views/projects/builds/_sidebar.html.haml @@ -44,15 +44,16 @@ %p.build-detail-row %span.build-light-text Erased: #{time_ago_with_tooltip(@build.erased_at)} - - elsif @build.artifacts_expired? - %p.build-detail-row.artifacts-expired.alert.alert-warning - The artifacts were removed #{time_ago_with_tooltip(@build.artifacts_expire_at)} - - elsif @build.artifacts_expire_at - %p.build-detail-row.artifacts-expired.alert.alert-info - The artifacts will be removed at #{time_ago_with_tooltip(@build.artifacts_expire_at)} - .pull-right - = link_to keep_artifacts_namespace_project_build_artifacts_path(@project.namespace, @project, @build), class: 'btn btn-sm btn-primary' do - Keep + - else + - if @build.artifacts_expired? + .artifacts-expired.alert.alert-warning + The artifacts were removed #{time_ago_with_tooltip(@build.artifacts_expire_at)} + - elsif @build.artifacts_expire_at + .artifacts-expired.alert.alert-warning + The artifacts will be removed in #{duration_in_words(@build.artifacts_expire_at, Time.now)} + .pull-right + = link_to keep_namespace_project_build_artifacts_path(@project.namespace, @project, @build), class: 'btn btn-xs btn-primary', method: :post do + Keep %p.build-detail-row %span.build-light-text Runner: - if @build.runner && current_user && current_user.admin diff --git a/app/workers/expire_build_artifacts.rb b/app/workers/expire_build_artifacts_worker.rb index 3d809d8ab6b..17b3b5f227f 100644 --- a/app/workers/expire_build_artifacts.rb +++ b/app/workers/expire_build_artifacts_worker.rb @@ -4,8 +4,9 @@ class ExpireBuildArtifacts def perform Rails.logger.info 'Cleaning old build artifacts' - builds = Ci::Build.with_artifacts_expired + builds = Ci::Build.with_expired_artifacts builds.find_each(batch_size: 50).each do |build| + Rails.logger.debug "Removing artifacts build #{build.id}..." build.erase_artifacts! end end |