2017-06-02 15:12:36 +00:00
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
2017-07-11 13:42:00 +00:00
|
|
|
def self.queue
|
2017-07-13 09:44:52 +00:00
|
|
|
@queue ||= BackgroundMigrationWorker.sidekiq_options['queue']
|
2017-07-11 13:42:00 +00:00
|
|
|
end
|
|
|
|
|
2017-06-02 15:12:36 +00:00
|
|
|
# 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)
|
2017-07-13 09:44:52 +00:00
|
|
|
enqueued = Sidekiq::Queue.new(self.queue)
|
|
|
|
scheduled = Sidekiq::ScheduledSet.new
|
2017-06-02 15:12:36 +00:00
|
|
|
|
2017-07-13 09:44:52 +00:00
|
|
|
[scheduled, enqueued].each do |queue|
|
|
|
|
queue.each do |job|
|
|
|
|
migration_class, migration_args = job.args
|
2017-06-02 15:12:36 +00:00
|
|
|
|
2017-07-13 09:44:52 +00:00
|
|
|
next unless job.queue == self.queue
|
|
|
|
next unless migration_class == steal_class
|
2017-06-02 15:12:36 +00:00
|
|
|
|
2017-07-14 10:48:11 +00:00
|
|
|
perform(migration_class, migration_args) if job.delete
|
2017-07-13 09:44:52 +00:00
|
|
|
end
|
2017-06-02 15:12:36 +00:00
|
|
|
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
|