diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2017-09-06 07:16:26 +0200 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-09-28 16:32:14 +0100 |
commit | f4de14d71f425dc14ee5837d96f4e9f42c7cc239 (patch) | |
tree | ef7d2183469853b049eee8326f66edd4a3744f68 /app/workers | |
parent | 38607b48b689b39721ff0cf7355ba2a176f4bf5e (diff) | |
download | gitlab-ce-f4de14d71f425dc14ee5837d96f4e9f42c7cc239.tar.gz |
Add support to migrate existing projects to Hashed Storage asynchashed-storage-migration-path
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/project_migrate_hashed_storage_worker.rb | 11 | ||||
-rw-r--r-- | app/workers/storage_migrator_worker.rb | 30 |
2 files changed, 41 insertions, 0 deletions
diff --git a/app/workers/project_migrate_hashed_storage_worker.rb b/app/workers/project_migrate_hashed_storage_worker.rb new file mode 100644 index 00000000000..ca276d7801c --- /dev/null +++ b/app/workers/project_migrate_hashed_storage_worker.rb @@ -0,0 +1,11 @@ +class ProjectMigrateHashedStorageWorker + include Sidekiq::Worker + include DedicatedSidekiqQueue + + def perform(project_id) + project = Project.find_by(id: project_id) + return if project.nil? || project.pending_delete? + + ::Projects::HashedStorageMigrationService.new(project, logger).execute + end +end diff --git a/app/workers/storage_migrator_worker.rb b/app/workers/storage_migrator_worker.rb new file mode 100644 index 00000000000..b48ead799b9 --- /dev/null +++ b/app/workers/storage_migrator_worker.rb @@ -0,0 +1,30 @@ +class StorageMigratorWorker + include Sidekiq::Worker + include DedicatedSidekiqQueue + + BATCH_SIZE = 100 + + def perform(start, finish) + projects = build_relation(start, finish) + + projects.with_route.find_each(batch_size: BATCH_SIZE) do |project| + Rails.logger.info "Starting storage migration of #{project.full_path} (ID=#{project.id})..." + + begin + project.migrate_to_hashed_storage! + rescue => err + Rails.logger.error("#{err.message} migrating storage of #{project.full_path} (ID=#{project.id}), trace - #{err.backtrace}") + end + end + end + + def build_relation(start, finish) + relation = Project + table = Project.arel_table + + relation = relation.where(table[:id].gteq(start)) if start + relation = relation.where(table[:id].lteq(finish)) if finish + + relation + end +end |