Need support for draining queues
anazar opened this issue · 3 comments
anazar commented
It would be great if we could support draining queues similar to how sidekiq does it here: https://github.com/mperham/sidekiq/wiki/Testing#testing-worker-queueing-fake
I would recommend 2 methods:
-
Executing all queued jobs by draining the queue for a specific worker
HardWorker.drain
-
Draining the entire queue
Que.drain_all
ZimbiX commented
ZimbiX commented
@bblimke As mentioned in the linked Discord conversation, you can start a Locker manually, and poll the jobs table row count to wait for completion (if it's for tests, you could use rspec-wait). Something like:
let(:locker) { Que::Locker.new }
let!(:que_sync_orig) { Que.run_synchronously }
before { Que.run_synchronously = false }
after do
locker.stop!
db[:que_jobs].delete
Que.run_synchronously = que_sync_orig
end
it 'drains' do
TestJob.enqueue
locker
with_wait(delay: 0.001) do
wait_for { db[:que_jobs].count }.to eq(0)
end
end