Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a Resque queue to SideKiq

I am trying to convert a Resque queue to Sidekiq. I've completed the entire setup for Sidekiq, and now am ready to add all my resque jobs to sidekiq ones.

My question is: Can I simply rename all the resque keys in redis to the corresponding sidekiq keys?

For instance, if I have a queue named "twitter", the redis key for resque is "resque:queue:twitter", but the key in sidekiq would be "queue:twitter". Could I simply rename "resque:queue:twitter" to "queue:twitter" ?

like image 244
Henley Avatar asked Dec 11 '12 03:12

Henley


People also ask

Is Sidekiq a queue?

Out-of-the-box Sidekiq uses a single queue named "default," but it's possible to create and use any number of other named queues if there is at least one Sidekiq worker configured to look at every queue.

Why does Sidekiq use Redis?

Sidekiq uses Redis as a job management store to process thousands of jobs per second.


2 Answers

Ok Finally Got it

There are few global command that I missed and rename is perhaps one of them.

Where you can rename the keys If you want

do something like this

redis.rename "resque:queue:twitter","queue:twitter" 

And see if it work

Cheers

Thanks for the question It just brushed up by redis knowledge

like image 103
Viren Avatar answered Sep 29 '22 11:09

Viren


Here is some code I used to migrate over our existing resque jobs to sidekiq. You can use this in the rails console.

['low', 'high', 'critical'].each do |queue|
  p [1, queue]
  old_queue = "resque:queue:#{queue}"
  new_queue = "queue:#{queue}"
  # $redis.ltrim new_queue, 0, 0 # can optionally clear out new queue, in case of multiple runs

  vals = $redis.lrange(old_queue, 0, -1)
  p [2, queue]
  $redis.pipelined do
    vals.each do |val|
      $redis.lpush(new_queue, val)
    end
  end
end

You can also just set:

Sidekiq.configure_server do |config|
  config.redis = { :namespace => 'resque' }
end
Sidekiq.configure_client do |config|
  config.redis = { :namespace => 'resque' }
end

and it will work out of the box. But after I deployed without this, I had pending jobs in both formats, so had to use the first code I pasted to migrate things over.

like image 35
Brian Armstrong Avatar answered Sep 29 '22 09:09

Brian Armstrong