Class: Gitlab::Cleanup::RemoteUploads

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/cleanup/remote_uploads.rb

Constant Summary collapse

BATCH_SIZE =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#loggerObject (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
# File 'lib/gitlab/cleanup/remote_uploads.rb', line 13

def run!(dry_run: false)
  unless configuration.enabled
    logger.warn "Object storage not enabled. Exit".color(:yellow)

    return
  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