Welcome to mirror list, hosted at ThFree Co, Russian Federation.

background_move_worker.rb « object_storage « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb51f0d7e1f4cdee082d83e807aa8a6b6257e40b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module ObjectStorage
  class BackgroundMoveWorker # rubocop:disable Scalability/IdempotentWorker
    include ApplicationWorker

    data_consistency :always
    include ObjectStorageQueue

    sidekiq_options retry: 5
    feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned
    loggable_arguments 0, 1, 2, 3

    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
      when Upload then subject.retrieve_uploader(mount_point)
      else
        subject.send(mount_point) # rubocop:disable GitlabSecurity/PublicSend
      end
    end
  end
end