Commit 6d41b9d2 authored by Allison Browne's avatar Allison Browne

Move Gitlab::Artifacts::MigrationHelper to the Ci namespace

Gitlab::Artifacts::MigrationHelper becomes Gitlab::Ci::Artifacts::MigrationHelper

issue: https://gitlab.com/gitlab-org/gitlab/-/issues/273605
parent fd580d00
# 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 StandardError => 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
# frozen_string_literal: true
module Gitlab
module Ci
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 StandardError => 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
end
......@@ -10,7 +10,7 @@ namespace :gitlab do
logger = Logger.new(STDOUT)
logger.info('Starting transfer of artifacts to remote storage')
helper = Gitlab::Artifacts::MigrationHelper.new
helper = Gitlab::Ci::Artifacts::MigrationHelper.new
begin
helper.migrate_to_remote_storage do |artifact|
......@@ -25,7 +25,7 @@ namespace :gitlab do
logger = Logger.new(STDOUT)
logger.info('Starting transfer of artifacts to local storage')
helper = Gitlab::Artifacts::MigrationHelper.new
helper = Gitlab::Ci::Artifacts::MigrationHelper.new
begin
helper.migrate_to_local_storage do |artifact|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment