Commit 7e22054a authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'osw-schedule-multiple-mr-assignees-ff-auto-enabling' into 'master'

Add methods to check dead and retrying jobs

See merge request gitlab-org/gitlab-ce!27149
parents e38fe79c 285fcb47
...@@ -58,11 +58,31 @@ module Gitlab ...@@ -58,11 +58,31 @@ module Gitlab
migration_class_for(class_name).new.perform(*arguments) migration_class_for(class_name).new.perform(*arguments)
end end
def self.exists?(migration_class) def self.exists?(migration_class, additional_queues = [])
enqueued = Sidekiq::Queue.new(self.queue) enqueued = Sidekiq::Queue.new(self.queue)
scheduled = Sidekiq::ScheduledSet.new scheduled = Sidekiq::ScheduledSet.new
[enqueued, scheduled].each do |queue| 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
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| queue.each do |job|
return true if job.queue == self.queue && job.args.first == migration_class return true if job.queue == self.queue && job.args.first == migration_class
end end
...@@ -70,9 +90,5 @@ module Gitlab ...@@ -70,9 +90,5 @@ module Gitlab
false false
end end
def self.migration_class_for(class_name)
const_get(class_name)
end
end end
end end
...@@ -195,4 +195,44 @@ describe Gitlab::BackgroundMigration do ...@@ -195,4 +195,44 @@ describe Gitlab::BackgroundMigration do
end end
end 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 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