summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-07-17 13:19:21 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-07-17 13:19:21 +0000
commit5c4f99a360aaeb5dc5c95d7e14f56a7cc23f2b29 (patch)
tree73cd4411063716f39cab0b2874d2d80071a949d3 /lib
parentc64fd519e58d5605d43baca11a892028c4390c61 (diff)
parente41d42d6a2f5775b8f165cb00617dc956d3ca097 (diff)
downloadgitlab-ce-5c4f99a360aaeb5dc5c95d7e14f56a7cc23f2b29.tar.gz
Merge branch 'fix/gb/process-scheduled-background-migrations' into 'master'
Process scheduled background migrations as well Closes #34951 See merge request !12787
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/background_migration.rb35
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/gitlab/background_migration.rb b/lib/gitlab/background_migration.rb
index d95ecd7b291..b0741b1fba7 100644
--- a/lib/gitlab/background_migration.rb
+++ b/lib/gitlab/background_migration.rb
@@ -1,24 +1,45 @@
module Gitlab
module BackgroundMigration
+ def self.queue
+ @queue ||= BackgroundMigrationWorker.sidekiq_options['queue']
+ end
+
# Begins stealing jobs from the background migrations queue, blocking the
# caller until all jobs have been completed.
#
+ # When a migration raises a StandardError is is going to be retries up to
+ # three times, for example, to recover from a deadlock.
+ #
+ # When Exception is being raised, it enqueues the migration again, and
+ # re-raises the exception.
+ #
# 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'])
+ enqueued = Sidekiq::Queue.new(self.queue)
+ scheduled = Sidekiq::ScheduledSet.new
- queue.each do |job|
- migration_class, migration_args = job.args
+ [scheduled, enqueued].each do |queue|
+ queue.each do |job|
+ migration_class, migration_args = job.args
- next unless migration_class == steal_class
+ next unless job.queue == self.queue
+ next unless migration_class == steal_class
- perform(migration_class, migration_args)
+ begin
+ perform(migration_class, migration_args, retries: 3) if job.delete
+ rescue Exception # rubocop:disable Lint/RescueException
+ BackgroundMigrationWorker # enqueue this migration again
+ .perform_async(migration_class, migration_args)
- job.delete
+ raise
+ end
+ end
end
end
+ ##
+ # Performs a background migration.
+ #
# class_name - The name of the background migration class as defined in the
# Gitlab::BackgroundMigration namespace.
#