diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:47 +0000 |
commit | 8f9beefac3774b30e911fb00a68f4c7a5244cf27 (patch) | |
tree | 919c3a043f8c10bc3f78f3f6e029acfb6b972556 /lib/tasks | |
parent | e4bf776a8829e5186a0f63603c0be627b891d80e (diff) | |
download | gitlab-ce-8f9beefac3774b30e911fb00a68f4c7a5244cf27.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/cleanup.rake | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake index c26aa848d5a..a56a0435673 100644 --- a/lib/tasks/gitlab/cleanup.rake +++ b/lib/tasks/gitlab/cleanup.rake @@ -64,6 +64,40 @@ namespace :gitlab do end end + desc 'GitLab | Cleanup | Clean orphan LFS file references' + task orphan_lfs_file_references: :gitlab_environment do + warn_user_is_not_gitlab + + project = find_project + + unless project + logger.info "Specify the project with PROJECT_ID={number} or PROJECT_PATH={namespace/project-name}".color(:red) + exit + end + + cleaner = Gitlab::Cleanup::OrphanLfsFileReferences.new( + project, + dry_run: dry_run?, + logger: logger, + limit: limit + ) + + cleaner.run! + + if dry_run? + logger.info "To clean up these files run this command with DRY_RUN=false".color(:yellow) + end + end + + desc 'GitLab | Cleanup | Clean orphan LFS files' + task orphan_lfs_files: :gitlab_environment do + warn_user_is_not_gitlab + + removed_files = RemoveUnreferencedLfsObjectsWorker.new.perform + + logger.info "Removed unreferenced LFS files: #{removed_files.count}".color(:green) + end + namespace :sessions do desc "GitLab | Cleanup | Sessions | Clean ActiveSession lookup keys" task active_sessions_lookup_keys: :gitlab_environment do @@ -136,6 +170,14 @@ namespace :gitlab do ENV['NICENESS'].presence end + def find_project + if ENV['PROJECT_ID'] + Project.find_by_id(ENV['PROJECT_ID']&.to_i) + elsif ENV['PROJECT_PATH'] + Project.find_by_full_path(ENV['PROJECT_PATH']) + end + end + # rubocop:disable Gitlab/RailsLogger def logger return @logger if defined?(@logger) |