Class: Gitlab::Cleanup::OrphanJobArtifactFiles

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/cleanup/orphan_job_artifact_files.rb

Constant Summary collapse

ABSOLUTE_ARTIFACT_DIR =
::JobArtifactUploader.root.freeze
LOST_AND_FOUND =
File.join(ABSOLUTE_ARTIFACT_DIR, '-', 'lost+found').freeze
BATCH_SIZE =
500
DEFAULT_NICENESS =
'best-effort'
VALID_NICENESS_LEVELS =
%w[none realtime best-effort idle].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dry_run: true, niceness: nil, logger: nil) ⇒ OrphanJobArtifactFiles

Returns a new instance of OrphanJobArtifactFiles.



17
18
19
20
21
22
23
24
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 17

def initialize(dry_run: true, niceness: nil, logger: nil)
  @dry_run = dry_run
  @niceness = (niceness || DEFAULT_NICENESS).downcase
  @logger = logger || Gitlab::AppLogger
  @total_found = @total_cleaned = 0

  new_batch!
end

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



14
15
16
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 14

def batch
  @batch
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



15
16
17
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 15

def dry_run
  @dry_run
end

#loggerObject (readonly)

Returns the value of attribute logger.



15
16
17
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 15

def logger
  @logger
end

#nicenessObject (readonly)

Returns the value of attribute niceness.



15
16
17
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 15

def niceness
  @niceness
end

#total_cleanedObject

Returns the value of attribute total_cleaned.



14
15
16
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 14

def total_cleaned
  @total_cleaned
end

#total_foundObject

Returns the value of attribute total_found.



14
15
16
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 14

def total_found
  @total_found
end

Instance Method Details

#run!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/cleanup/orphan_job_artifact_files.rb', line 26

def run!
  log_info('Looking for orphan job artifacts to clean up')

  find_artifacts do |artifact_file|
    batch << artifact_file

    clean_batch! if batch.full?

    if limit_reached?
      log_info("Exiting due to reaching limit of #{limit}.")
      break
    end
  end

  clean_batch!

  log_info("Processed #{total_found} job artifact(s) to find and cleaned #{total_cleaned} orphan(s).")
end