debian-mirror-gitlab/app/models/ci/deleted_object.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
928 B
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module Ci
2021-10-27 15:23:28 +05:30
class DeletedObject < Ci::ApplicationRecord
2021-01-03 14:25:43 +05:30
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-04-17 20:07:23 +05:30
def self.bulk_import(artifacts, pick_up_at = nil)
2021-01-03 14:25:43 +05:30
attributes = artifacts.each.with_object([]) do |artifact, accumulator|
2021-04-17 20:07:23 +05:30
record = artifact.to_deleted_object_attrs(pick_up_at)
2021-01-03 14:25:43 +05:30
accumulator << record if record[:store_dir] && record[:file]
end
2023-04-23 21:23:45 +05:30
insert_all(attributes) if attributes.any?
2021-01-03 14:25:43 +05:30
end
def delete_file_from_storage
file.remove!
true
2022-08-27 11:52:29 +05:30
rescue StandardError => e
Gitlab::ErrorTracking.track_exception(e)
2021-01-03 14:25:43 +05:30
false
end
end
end