Commit 5fc9f38e authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'custom-logic-to-steal-background-jobs' into 'master'

Allow custom predicate to steal BG jobs

See merge request gitlab-org/gitlab!35464
parents a6d90fcc 6b665859
......@@ -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