diff options
author | Toon Claes <toon@gitlab.com> | 2019-06-13 23:07:59 +0200 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2019-06-28 10:02:18 +0200 |
commit | dabd91b2c8a42ac0d0c357190002a5a4b96a57a6 (patch) | |
tree | 6010ff883161d0df297005e9fc1c66ce845bf482 /lib/tasks | |
parent | 8df6508ca35f211b8ded2291785751bdbc4a8c1a (diff) | |
download | gitlab-ce-dabd91b2c8a42ac0d0c357190002a5a4b96a57a6.tar.gz |
Add rake task to clean orphan artifact filestc-rake-orphan-artifacts
This adds the rake task rake
gitlab:cleanup:orphan_job_artifact_files. This rake task cleans all
orphan job artifact files it can find on disk.
It performs a search on the complete folder of all artifacts on
disk. Then it filters out all the job artifact ID for which it could
not find a record with matching ID in the database. For these, the
file is deleted from disk.
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/cleanup.rake | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake index 760331620ef..105ef417df3 100644 --- a/lib/tasks/gitlab/cleanup.rake +++ b/lib/tasks/gitlab/cleanup.rake @@ -115,6 +115,18 @@ namespace :gitlab do end end + desc 'GitLab | Cleanup | Clean orphan job artifact files' + task orphan_job_artifact_files: :gitlab_environment do + warn_user_is_not_gitlab + + cleaner = Gitlab::Cleanup::OrphanJobArtifactFiles.new(limit: limit, dry_run: dry_run?, niceness: niceness, logger: logger) + cleaner.run! + + if dry_run? + logger.info "To clean up these files run this command with DRY_RUN=false".color(:yellow) + end + end + def remove? ENV['REMOVE'] == 'true' end @@ -123,12 +135,25 @@ namespace :gitlab do ENV['DRY_RUN'] != 'false' end + def debug? + ENV['DEBUG'].present? + end + + def limit + ENV['LIMIT']&.to_i + end + + def niceness + ENV['NICENESS'].presence + end + def logger return @logger if defined?(@logger) @logger = if Rails.env.development? || Rails.env.production? Logger.new(STDOUT).tap do |stdout_logger| stdout_logger.extend(ActiveSupport::Logger.broadcast(Rails.logger)) + stdout_logger.level = debug? ? Logger::DEBUG : Logger::INFO end else Rails.logger |