2020-10-13 11:08:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
2021-08-03 02:08:50 -04:00
|
|
|
class DeletedObject < Ci::ApplicationRecord
|
2020-10-13 11:08:53 -04:00
|
|
|
mount_uploader :file, DeletedObjectUploader
|
|
|
|
|
|
|
|
scope :ready_for_destruction, ->(limit) do
|
|
|
|
where('pick_up_at < ?', Time.current).limit(limit)
|
|
|
|
end
|
|
|
|
|
|
|
|
scope :lock_for_destruction, ->(limit) do
|
|
|
|
ready_for_destruction(limit)
|
|
|
|
.select(:id)
|
|
|
|
.order(:pick_up_at)
|
|
|
|
.lock('FOR UPDATE SKIP LOCKED')
|
|
|
|
end
|
|
|
|
|
2021-03-12 16:09:12 -05:00
|
|
|
def self.bulk_import(artifacts, pick_up_at = nil)
|
2020-10-13 11:08:53 -04:00
|
|
|
attributes = artifacts.each.with_object([]) do |artifact, accumulator|
|
2021-03-12 16:09:12 -05:00
|
|
|
record = artifact.to_deleted_object_attrs(pick_up_at)
|
2020-10-13 11:08:53 -04:00
|
|
|
accumulator << record if record[:store_dir] && record[:file]
|
|
|
|
end
|
|
|
|
|
|
|
|
self.insert_all(attributes) if attributes.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_file_from_storage
|
|
|
|
file.remove!
|
|
|
|
true
|
2022-08-09 11:11:31 -04:00
|
|
|
rescue StandardError => e
|
|
|
|
Gitlab::ErrorTracking.track_exception(e)
|
2020-10-13 11:08:53 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|