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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/migrations/background_migration_helpers.rb')
-rw-r--r--lib/gitlab/database/migrations/background_migration_helpers.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/gitlab/database/migrations/background_migration_helpers.rb b/lib/gitlab/database/migrations/background_migration_helpers.rb
index 28491a934a0..19d80ba1d64 100644
--- a/lib/gitlab/database/migrations/background_migration_helpers.rb
+++ b/lib/gitlab/database/migrations/background_migration_helpers.rb
@@ -264,6 +264,34 @@ module Gitlab
migration
end
+ # Force a background migration to complete.
+ #
+ # WARNING: This method will block the caller and move the background migration from an
+ # asynchronous migration to a synchronous migration.
+ #
+ # 1. Steal work from sidekiq and perform immediately (avoid duplicates generated by step 2).
+ # 2. Process any pending tracked jobs.
+ # 3. Steal work from sidekiq and perform immediately (clear anything left from step 2).
+ # 4. Optionally remove job tracking information.
+ #
+ # This method does not garauntee that all jobs completed successfully.
+ def finalize_background_migration(class_name, delete_tracking_jobs: ['succeeded'])
+ # Empty the sidekiq queue.
+ Gitlab::BackgroundMigration.steal(class_name)
+
+ # Process pending tracked jobs.
+ jobs = Gitlab::Database::BackgroundMigrationJob.pending.for_migration_class(class_name)
+ jobs.find_each do |job|
+ BackgroundMigrationWorker.new.perform(job.class_name, job.arguments)
+ end
+
+ # Empty the sidekiq queue.
+ Gitlab::BackgroundMigration.steal(class_name)
+
+ # Delete job tracking rows.
+ delete_job_tracking(class_name, status: delete_tracking_jobs) if delete_tracking_jobs
+ end
+
def perform_background_migration_inline?
Rails.env.test? || Rails.env.development?
end
@@ -304,6 +332,12 @@ module Gitlab
end
end
+ def delete_job_tracking(class_name, status: 'succeeded')
+ status = Array(status).map { |s| Gitlab::Database::BackgroundMigrationJob.statuses[s] }
+ jobs = Gitlab::Database::BackgroundMigrationJob.where(status: status).for_migration_class(class_name)
+ jobs.each_batch { |batch| batch.delete_all }
+ end
+
private
def track_in_database(class_name, arguments)