background_migration.rb 1.12 KB
Newer Older
1 2
module Gitlab
  module BackgroundMigration
3
    def self.queue
4
      @queue ||= BackgroundMigrationWorker.sidekiq_options['queue']
5 6
    end

7 8 9 10 11
    # 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)
12 13
      enqueued = Sidekiq::Queue.new(self.queue)
      scheduled = Sidekiq::ScheduledSet.new
14

15 16 17
      [scheduled, enqueued].each do |queue|
        queue.each do |job|
          migration_class, migration_args = job.args
18

19 20
          next unless job.queue == self.queue
          next unless migration_class == steal_class
21

22
          perform(migration_class, migration_args) if job.delete
23
        end
24 25 26 27 28 29 30 31 32 33 34 35 36
      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