Commit 285fcb47 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Add methods to check dead and retrying jobs

It adds two methods for checking if a background job
(for a given class) has dead or retrying jobs.
parent 61ed9239
......@@ -58,21 +58,37 @@ module Gitlab
migration_class_for(class_name).new.perform(*arguments)
end
def self.exists?(migration_class)
def self.exists?(migration_class, additional_queues = [])
enqueued = Sidekiq::Queue.new(self.queue)
scheduled = Sidekiq::ScheduledSet.new
[enqueued, scheduled].each do |queue|
queue.each do |job|
return true if job.queue == self.queue && job.args.first == migration_class
enqueued_job?([enqueued, scheduled], migration_class)
end
def self.dead_jobs?(migration_class)
dead_set = Sidekiq::DeadSet.new
enqueued_job?([dead_set], migration_class)
end
false
def self.retrying_jobs?(migration_class)
retry_set = Sidekiq::RetrySet.new
enqueued_job?([retry_set], migration_class)
end
def self.migration_class_for(class_name)
const_get(class_name)
end
def self.enqueued_job?(queues, migration_class)
queues.each do |queue|
queue.each do |job|
return true if job.queue == self.queue && job.args.first == migration_class
end
end
false
end
end
end
......@@ -195,4 +195,44 @@ describe Gitlab::BackgroundMigration do
end
end
end
describe '.dead_jobs?' do
let(:queue) do
[double(args: ['Foo', [10, 20]], queue: described_class.queue)]
end
context 'when there are dead jobs present' do
before do
allow(Sidekiq::DeadSet).to receive(:new).and_return(queue)
end
it 'returns true if specific job exists' do
expect(described_class.dead_jobs?('Foo')).to eq(true)
end
it 'returns false if specific job does not exist' do
expect(described_class.dead_jobs?('Bar')).to eq(false)
end
end
end
describe '.retrying_jobs?' do
let(:queue) do
[double(args: ['Foo', [10, 20]], queue: described_class.queue)]
end
context 'when there are dead jobs present' do
before do
allow(Sidekiq::RetrySet).to receive(:new).and_return(queue)
end
it 'returns true if specific job exists' do
expect(described_class.retrying_jobs?('Foo')).to eq(true)
end
it 'returns false if specific job does not exist' do
expect(described_class.retrying_jobs?('Bar')).to eq(false)
end
end
end
end
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