2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
module ObjectStorage
|
2020-04-08 14:13:33 +05:30
|
|
|
class BackgroundMoveWorker # rubocop:disable Scalability/IdempotentWorker
|
2018-05-09 12:01:36 +05:30
|
|
|
include ApplicationWorker
|
|
|
|
include ObjectStorageQueue
|
|
|
|
|
|
|
|
sidekiq_options retry: 5
|
2019-12-21 20:55:43 +05:30
|
|
|
feature_category_not_owned!
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
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-12-21 20:55:43 +05:30
|
|
|
when Upload then subject.retrieve_uploader(mount_point)
|
2018-05-09 12:01:36 +05:30
|
|
|
else
|
|
|
|
subject.send(mount_point) # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|