Resque Compatibility

Mike Perham edited this page May 26, 2016 · 30 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 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)

Sidekiq::Client also has enqueue_in for compatibility with resque-scheduler.

Performance

resque and delayed_job use the same inefficient, single-threaded process design. Sidekiq is typically an order of magnitude faster.

Functionality

Sidekiq includes a lot more functionality than Resque out of the box. For example, Sidekiq includes most of the functionality in resque-scheduler, resque-web, resque_mailer and resque-retry in its gem with little if any custom configuration required.

Plugins

Sidekiq does not support Resque's callback-based plugins. It provides a Middleware API for registering your own hooks to execute code around the processing of a job.

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.

Redis

If your Resque processors are using a namespace, make sure you configure Sidekiq to use the same namespace. Add this to your sidekiq.rb initializer.

# Add gem 'redis-namespace' to your Gemfile too
Sidekiq.configure_client do |config|
  config.redis = { namespace: 'resque' }
end
Sidekiq.configure_server do |config|
  config.redis = { namespace: 'resque' }
end

Previous: Middleware Next: Logging