Commit ce1fb7b9 authored by Stan Hu's avatar Stan Hu

Merge branch 'ab-namespace-ci-artifacts-migrationHelper' into 'master'

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

See merge request gitlab-org/gitlab!59920
parents 2b4a7ee4 6d41b9d2
# 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 ...@@ -10,7 +10,7 @@ namespace :gitlab do
logger = Logger.new(STDOUT) logger = Logger.new(STDOUT)
logger.info('Starting transfer of artifacts to remote storage') logger.info('Starting transfer of artifacts to remote storage')
helper = Gitlab::Artifacts::MigrationHelper.new helper = Gitlab::Ci::Artifacts::MigrationHelper.new
begin begin
helper.migrate_to_remote_storage do |artifact| helper.migrate_to_remote_storage do |artifact|
...@@ -25,7 +25,7 @@ namespace :gitlab do ...@@ -25,7 +25,7 @@ namespace :gitlab do
logger = Logger.new(STDOUT) logger = Logger.new(STDOUT)
logger.info('Starting transfer of artifacts to local storage') logger.info('Starting transfer of artifacts to local storage')
helper = Gitlab::Artifacts::MigrationHelper.new helper = Gitlab::Ci::Artifacts::MigrationHelper.new
begin begin
helper.migrate_to_local_storage do |artifact| 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