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
|
|
|
|
include ObjectStorageQueue
|
|
|
|
|
|
|
|
sidekiq_options retry: 5
|
2019-10-18 11:11:44 +00:00
|
|
|
feature_category_not_owned!
|
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
|