Class: Gitlab::Cleanup::OrphanJobArtifactFinalObjects::BatchFromStorage
- Inherits:
-
Object
- Object
- Gitlab::Cleanup::OrphanJobArtifactFinalObjects::BatchFromStorage
- Defined in:
- lib/gitlab/cleanup/orphan_job_artifact_final_objects/batch_from_storage.rb
Instance Method Summary collapse
-
#initialize(fog_collection, bucket_prefix: nil) ⇒ BatchFromStorage
constructor
A new instance of BatchFromStorage.
- #orphan_objects ⇒ Object
Constructor Details
#initialize(fog_collection, bucket_prefix: nil) ⇒ BatchFromStorage
Returns a new instance of BatchFromStorage.
7 8 9 10 |
# File 'lib/gitlab/cleanup/orphan_job_artifact_final_objects/batch_from_storage.rb', line 7 def initialize(fog_collection, bucket_prefix: nil) @fog_collection = fog_collection @bucket_prefix = bucket_prefix end |
Instance Method Details
#orphan_objects ⇒ Object
12 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 |
# File 'lib/gitlab/cleanup/orphan_job_artifact_final_objects/batch_from_storage.rb', line 12 def orphan_objects objects = {} fog_collection.each_file_this_page do |fog_file| next unless in_final_location?(fog_file.key) objects[path_without_bucket_prefix(fog_file.key)] = fog_file end return [] unless objects.any? # First we exclude all objects that have matching existing job artifact record in the DB paths_with_job_artifact_records(objects.keys).each do |non_orphan_path| objects.delete(non_orphan_path) end return [] unless objects.any? # Next, if there were no matching job artifact record for the remaining paths, we want to # check if there is a pending direct upload for the given path, if found, they are not considered orphans. paths_with_pending_direct_uploads(objects.keys).each do |non_orphan_path| objects.delete(non_orphan_path) end # Just to keep the lexicographic order of objects objects.values.sort_by(&:key) end |