Skip to content

Resque Compatibility

dclausen edited this page Nov 2, 2012 · 20 revisions

I try to make Sidekiq compatible with Resque where possible and appropriate; this makes it easy to try out Sidekiq for those who are already using Resque.

  • Sidekiq uses the exact same message format as Resque in redis so it can process the exact same messages.
  • Because of this, the Resque client API can push messages onto Redis for Sidekiq to process.
  • Sidekiq exposes the exact same metrics so the resque-web interface can be used to monitor Sidekiq. I do strongly recommend using sidekiq-web though since there are differences in how Sidekiq and resque treat failures.

Sidekiq does require a slightly different worker API because your worker must be threadsafe. Asking for a class method to be threadsafe is a hilarious joke to most software developers:

resque:

class MyWorker
  def self.perform(name, count)
    # do something
  end
end

sidekiq:

class MyWorker
  include Sidekiq::Worker
  def perform(name, count)
    # do something
  end
end

Not a huge change but one that should make writing workers easier and more intuitive.

Client API

Sidekiq has an identical API for pushing jobs onto the queue so you can simply search and replace in your project:

resque:

Resque.enqueue(MyWorker, 'bob', 1)

sidekiq:

Sidekiq::Client.enqueue(MyWorker, 'bob', 1)
# equivalent to:
MyWorker.perform_async('bob', 1)

Performance

resque and delayed_job use the same inefficient, single-threaded process design. Sidekiq will use dramatically less resources so your processing farm might need 1 machine rather than 10.

Monitoring

Sidekiq emits the same metrics as Resque for monitoring purposes. You can actually use resque-web to monitor Sidekiq, just make sure you use the exact same Redis configuration as Resque, including the namespace (which is resque).

You can set Sidekiq to use the Resque namespace via the configure_server and configure_client blocks:

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

Don't forget to provide the :url if you're using a custom Redis url (see Advanced Options for more detail).

Plugins

Sidekiq does not support Resque's callback-based plugins. It provides a middleware API for registering your own plugins to execute code before/after a message is processed.

Limitations

Jobs enqueued with the resque client API do not have parameters like retry in the payload. This means that jobs will not be automatically retried if they fail. Please migrate your code to use the Sidekiq API to automatically pick up this feature or other features that rely on such parameters.

Clone this wiki locally