mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Ensure that all jobs are drained
Even when workers create new jobs when drained.
This commit is contained in:
parent
c4d56ab27b
commit
d19af9c102
2 changed files with 34 additions and 2 deletions
|
@ -93,8 +93,9 @@ module Sidekiq
|
|||
|
||||
# Drain all queued jobs across all workers
|
||||
def drain_all
|
||||
jobs.keys.each(&:drain)
|
||||
clear_all
|
||||
until jobs.values.all?(&:empty?) do
|
||||
jobs.keys.each(&:drain)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -129,6 +129,15 @@ class TestTesting < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class ThirdWorker
|
||||
include Sidekiq::Worker
|
||||
class_attribute :count
|
||||
def perform
|
||||
FirstWorker.perform_async
|
||||
SecondWorker.perform_async
|
||||
end
|
||||
end
|
||||
|
||||
it 'clears jobs across all workers' do
|
||||
Sidekiq::Worker.jobs.clear
|
||||
FirstWorker.count = 0
|
||||
|
@ -177,5 +186,27 @@ class TestTesting < MiniTest::Unit::TestCase
|
|||
assert_equal 1, FirstWorker.count
|
||||
assert_equal 1, SecondWorker.count
|
||||
end
|
||||
|
||||
it 'drains jobs across all workers even when workers create new jobs' do
|
||||
Sidekiq::Worker.jobs.clear
|
||||
FirstWorker.count = 0
|
||||
SecondWorker.count = 0
|
||||
|
||||
assert_equal 0, ThirdWorker.jobs.size
|
||||
|
||||
assert_equal 0, FirstWorker.count
|
||||
assert_equal 0, SecondWorker.count
|
||||
|
||||
ThirdWorker.perform_async
|
||||
|
||||
assert_equal 1, ThirdWorker.jobs.size
|
||||
|
||||
Sidekiq::Worker.drain_all
|
||||
|
||||
assert_equal 0, ThirdWorker.jobs.size
|
||||
|
||||
assert_equal 1, FirstWorker.count
|
||||
assert_equal 1, SecondWorker.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue