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

migration_helper.rb « artifacts « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f047ab3ea81800cf278acc7cac530f34ce663f5 (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
# frozen_string_literal: true

module Gitlab
  module Artifacts
    class MigrationHelper
      def migrate_to_remote_storage(&block)
        artifacts = ::Ci::JobArtifact.with_files_stored_locally
        migrate(artifacts, ObjectStorage::Store::REMOTE, &block)
      end

      def migrate_to_local_storage(&block)
        artifacts = ::Ci::JobArtifact.with_files_stored_remotely
        migrate(artifacts, ObjectStorage::Store::LOCAL, &block)
      end

      private

      def batch_size
        ENV.fetch('MIGRATION_BATCH_SIZE', 10).to_i
      end

      def migrate(artifacts, store, &block)
        artifacts.find_each(batch_size: batch_size) do |artifact| # rubocop:disable CodeReuse/ActiveRecord
          artifact.file.migrate!(store)

          yield artifact if block
        rescue => e
          raise StandardError.new("Failed to transfer artifact of type #{artifact.file_type} and ID #{artifact.id} with error: #{e.message}")
        end
      end
    end
  end
end