summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-06-02 17:12:36 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-06-12 13:24:04 +0200
commitd83ee2bbd10d8fe2f2e9521bb3c266cf696aa98c (patch)
tree7cf1c328790afd76c13fd553eb30786a14928835 /lib/gitlab/background_migration.rb
parent5478ff6dc2ad59a7c7d91f61339e8acee9bbb434 (diff)
downloadgitlab-ce-d83ee2bbd10d8fe2f2e9521bb3c266cf696aa98c.tar.gz
Add the ability to perform background migrations
Background migrations can be used to perform long running data migrations without these blocking a deployment procedure. See MR https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11854 for more information.
Diffstat (limited to 'lib/gitlab/background_migration.rb')
-rw-r--r--lib/gitlab/background_migration.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration.rb b/lib/gitlab/background_migration.rb
new file mode 100644
index 00000000000..914a3b72abd
--- /dev/null
+++ b/lib/gitlab/background_migration.rb
@@ -0,0 +1,31 @@
+module Gitlab
+ module BackgroundMigration
+ # Begins stealing jobs from the background migrations queue, blocking the
+ # caller until all jobs have been completed.
+ #
+ # steal_class - The name of the class for which to steal jobs.
+ def self.steal(steal_class)
+ queue = Sidekiq::Queue.
+ new(BackgroundMigrationWorker.sidekiq_options['queue'])
+
+ queue.each do |job|
+ migration_class, migration_args = job.args
+
+ next unless migration_class == steal_class
+
+ perform(migration_class, migration_args)
+
+ job.delete
+ end
+ end
+
+ # class_name - The name of the background migration class as defined in the
+ # Gitlab::BackgroundMigration namespace.
+ #
+ # arguments - The arguments to pass to the background migration's "perform"
+ # method.
+ def self.perform(class_name, arguments)
+ const_get(class_name).new.perform(*arguments)
+ end
+ end
+end