Commit 388abbd1 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract background migratons queue class method

parent c17b1d5f
module Gitlab module Gitlab
module BackgroundMigration module BackgroundMigration
def self.queue
BackgroundMigrationWorker.sidekiq_options['queue']
end
# Begins stealing jobs from the background migrations queue, blocking the # Begins stealing jobs from the background migrations queue, blocking the
# caller until all jobs have been completed. # caller until all jobs have been completed.
# #
# steal_class - The name of the class for which to steal jobs. # steal_class - The name of the class for which to steal jobs.
def self.steal(steal_class) def self.steal(steal_class)
queue = Sidekiq::Queue queue = Sidekiq::Queue.new(self.queue)
.new(BackgroundMigrationWorker.sidekiq_options['queue'])
queue.each do |job| queue.each do |job|
migration_class, migration_args = job.args migration_class, migration_args = job.args
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::BackgroundMigration do describe Gitlab::BackgroundMigration do
describe '.queue' do
it 'returns background migration worker queue' do
expect(described_class.queue)
.to eq BackgroundMigrationWorker.sidekiq_options['queue']
end
end
describe '.steal' do describe '.steal' do
it 'steals jobs from a queue' do context 'when there are enqueued jobs present' do
queue = [double(:job, args: ['Foo', [10, 20]])] let(:queue) { [double(:job, args: ['Foo', [10, 20]])] }
before do
allow(Sidekiq::Queue).to receive(:new) allow(Sidekiq::Queue).to receive(:new)
.with(BackgroundMigrationWorker.sidekiq_options['queue']) .with(described_class.queue)
.and_return(queue) .and_return(queue)
end
it 'steals jobs from a queue' do
expect(queue[0]).to receive(:delete) expect(queue[0]).to receive(:delete)
expect(described_class).to receive(:perform).with('Foo', [10, 20]) expect(described_class).to receive(:perform).with('Foo', [10, 20])
...@@ -17,12 +27,6 @@ describe Gitlab::BackgroundMigration do ...@@ -17,12 +27,6 @@ describe Gitlab::BackgroundMigration do
end end
it 'does not steal jobs for a different migration' do it 'does not steal jobs for a different migration' do
queue = [double(:job, args: ['Foo', [10, 20]])]
allow(Sidekiq::Queue).to receive(:new)
.with(BackgroundMigrationWorker.sidekiq_options['queue'])
.and_return(queue)
expect(described_class).not_to receive(:perform) expect(described_class).not_to receive(:perform)
expect(queue[0]).not_to receive(:delete) expect(queue[0]).not_to receive(:delete)
...@@ -30,6 +34,7 @@ describe Gitlab::BackgroundMigration do ...@@ -30,6 +34,7 @@ describe Gitlab::BackgroundMigration do
described_class.steal('Bar') described_class.steal('Bar')
end end
end end
end
describe '.perform' do describe '.perform' do
it 'performs a background migration' do it 'performs a background migration' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment