Class: Gitlab::Cleanup::OrphanJobArtifactFinalObjects::BatchFromList
- Inherits:
- 
      Object
      
        - Object
- Gitlab::Cleanup::OrphanJobArtifactFinalObjects::BatchFromList
 
- Includes:
- StorageHelpers, Utils::StrongMemoize
- Defined in:
- lib/gitlab/cleanup/orphan_job_artifact_final_objects/batch_from_list.rb
Constant Summary collapse
- GOOGLE_PROVIDER =
- 'google'
Instance Method Summary collapse
- 
  
    
      #initialize(entries, logger: Gitlab::AppLogger)  ⇒ BatchFromList 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of BatchFromList. 
- #orphan_objects ⇒ Object
Methods included from StorageHelpers
#artifacts_directory, #bucket, #bucket_prefix, #configuration, #connection
Constructor Details
#initialize(entries, logger: Gitlab::AppLogger) ⇒ BatchFromList
Returns a new instance of BatchFromList.
| 12 13 14 15 | # File 'lib/gitlab/cleanup/orphan_job_artifact_final_objects/batch_from_list.rb', line 12 def initialize(entries, logger: Gitlab::AppLogger) @entries = entries @logger = logger end | 
Instance Method Details
#orphan_objects ⇒ Object
| 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | # File 'lib/gitlab/cleanup/orphan_job_artifact_final_objects/batch_from_list.rb', line 17 def orphan_objects objects = {} each_fog_file do |fog_file| objects[path_without_bucket_prefix(fog_file.key)] = fog_file end return [] unless objects.any? # During the process of identifying orphan objects, there might be a very # tiny window for a race condition. This happens between checking for existence of # job artifact DB record, and the checking of pending direct upload entry in redis. # It may be possible that a pending direct upload completes (creates DB record and # deletes redis entry) only right after the script had already checked for the matching # job artifact record and not finding one, but right before the script checks for a # pending upload entry, thus the script finding no redis entry anymore, which would # lead to a false positive orphan object. # # This is why for sanity check, we still want to make sure that there is no matching # job artifact record in the database before we delete the object. paths_with_job_artifact_records(objects.keys).each do |non_orphan_path| log_skipping_no_artifact_record(non_orphan_path) objects.delete(non_orphan_path) end return [] unless objects.any? # Just to keep the lexicographic order of objects objects.values.sort_by(&:key) end |