Commit 6b665859 authored by pbair's avatar pbair

Allow custom predicate to steal BG jobs

Modify the BackgroundMigration.steal method to accept an optional
predicate block that will only steal jobs matching the class name for
which the block returns true.
parent dcc784c4
......@@ -33,6 +33,7 @@ module Gitlab
next unless job.queue == self.queue
next unless migration_class == steal_class
next if block_given? && !(yield migration_args)
begin
perform(migration_class, migration_args) if job.delete
......
......@@ -47,6 +47,25 @@ RSpec.describe Gitlab::BackgroundMigration do
described_class.steal('Bar')
end
context 'when a custom predicate is given' do
it 'steals jobs that match the predicate' do
expect(queue[0]).to receive(:delete).and_return(true)
expect(described_class).to receive(:perform)
.with('Foo', [10, 20])
described_class.steal('Foo') { |(arg1, arg2)| arg1 == 10 && arg2 == 20 }
end
it 'does not steal jobs that do not match the predicate' do
expect(described_class).not_to receive(:perform)
expect(queue[0]).not_to receive(:delete)
described_class.steal('Foo') { |(arg1, _)| arg1 == 5 }
end
end
end
context 'when one of the jobs raises an error' 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