Move Sidekiq jobs
I was looking for a way to move jobs from one high priority queue to another less prioritized in Sidekiq.
There is nothing built into Sidekiq to complete this, but obviously, you can just use Redis commands to do it.
Here is code snippet to do that.
from_queue_name = 'default'
to_queue_name = 'low'
count_block = proc { Sidekiq.redis do |conn|
conn.llen("queue:#{from_queue_name}")
end }
while count_block.call > 0
Sidekiq.redis do |conn|
conn.rpoplpush "queue:#{from_queue_name}", "queue:#{to_queue_name}"
end
end
This code snippet will move all the items from one queue to another until there are no more jobs.