2018-06-27 07:31:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-21 21:09:53 +00:00
|
|
|
module ObjectStorage
|
2020-02-19 18:09:10 +00:00
|
|
|
class BackgroundMoveWorker # rubocop:disable Scalability/IdempotentWorker
|
2018-02-21 21:09:53 +00:00
|
|
|
include ApplicationWorker
|
2021-07-21 12:09:35 +00:00
|
|
|
|
|
|
|
data_consistency :always
|
2018-02-21 21:09:53 +00:00
|
|
|
include ObjectStorageQueue
|
|
|
|
|
|
|
|
sidekiq_options retry: 5
|
2022-04-05 12:10:23 +00:00
|
|
|
feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned
|
2020-06-12 12:08:56 +00:00
|
|
|
loggable_arguments 0, 1, 2, 3
|
2018-02-21 21:09:53 +00:00
|
|
|
|
|
|
|
def perform(uploader_class_name, subject_class_name, file_field, subject_id)
|
|
|
|
uploader_class = uploader_class_name.constantize
|
|
|
|
subject_class = subject_class_name.constantize
|
|
|
|
|
|
|
|
return unless uploader_class < ObjectStorage::Concern
|
|
|
|
return unless uploader_class.object_store_enabled?
|
|
|
|
return unless uploader_class.background_upload_enabled?
|
|
|
|
|
|
|
|
subject = subject_class.find(subject_id)
|
|
|
|
uploader = build_uploader(subject, file_field&.to_sym)
|
|
|
|
uploader.migrate!(ObjectStorage::Store::REMOTE)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_uploader(subject, mount_point)
|
|
|
|
case subject
|
2019-10-03 00:05:59 +00:00
|
|
|
when Upload then subject.retrieve_uploader(mount_point)
|
2018-02-21 21:09:53 +00:00
|
|
|
else
|
|
|
|
subject.send(mount_point) # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|