Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need support for draining queues #354

Open
anazar opened this issue Mar 21, 2022 · 3 comments
Open

Need support for draining queues #354

anazar opened this issue Mar 21, 2022 · 3 comments

Comments

@anazar
Copy link

anazar commented Mar 21, 2022

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:

  1. Executing all queued jobs by draining the queue for a specific worker
    HardWorker.drain

  2. Draining the entire queue
    Que.drain_all

@ZimbiX
Copy link
Member

ZimbiX commented Mar 21, 2022

@bblimke
Copy link

bblimke commented Mar 2, 2023

@ZimbiX do you have any workaround applied?

@ZimbiX
Copy link
Member

ZimbiX commented Mar 2, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants