diff options
Diffstat (limited to 'lib/tasks/gitlab/cleanup.rake')
-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) |