Class: Gitlab::Cleanup::RemoteUploads
- Inherits:
-
Object
- Object
- Gitlab::Cleanup::RemoteUploads
- Defined in:
- lib/gitlab/cleanup/remote_uploads.rb
Constant Summary collapse
- BATCH_SIZE =
100
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logger: nil) ⇒ RemoteUploads
constructor
A new instance of RemoteUploads.
- #run!(dry_run: false) ⇒ Object
Constructor Details
#initialize(logger: nil) ⇒ RemoteUploads
Returns a new instance of RemoteUploads.
9 10 11 |
# File 'lib/gitlab/cleanup/remote_uploads.rb', line 9 def initialize(logger: nil) @logger = logger || Gitlab::AppLogger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/gitlab/cleanup/remote_uploads.rb', line 5 def logger @logger end |
Instance Method Details
#run!(dry_run: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/cleanup/remote_uploads.rb', line 13 def run!(dry_run: false) unless configuration.enabled logger.warn Rainbow("Object storage not enabled. Exit").yellow return end if bucket_prefix.present? = "Uploads are configured with a bucket prefix '#{bucket_prefix}'.\n" += "Unfortunately, prefixes are not supported for this Rake task.\n" # At the moment, Fog does not provide a cloud-agnostic way of iterating through a bucket with a prefix. raise end logger.info "Looking for orphaned remote uploads to remove#{'. Dry run' if dry_run}..." each_orphan_file do |file| info = if dry_run "Can be moved to lost and found: #{file.key}" else new_path = move_to_lost_and_found(file) "Moved to lost and found: #{file.key} -> #{new_path}" end logger.info(info) end end |