-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Getting Started
Sidekiq makes every effort to make usage with modern Rails applications as simple as possible. Please see the ActiveJob page if you want to use Sidekiq with ActiveJob.
- Add sidekiq to your Gemfile:
gem 'sidekiq'- Add a worker in
app/workersto process jobs asynchronously:
rails g sidekiq:worker Hard # will create app/workers/hard_worker.rbclass HardWorker
include Sidekiq::Worker
def perform(name, count)
# do something
end
end- Create a job to be processed asynchronously:
HardWorker.perform_async('bob', 5)Note that perform is an instance method, whereas perform_async is called on the class.
You can also create a job to be processed in the future:
HardWorker.perform_in(5.minutes, 'bob', 5)You can also create jobs by calling the delay method on a class method for versions < 5.0:
User.delay.do_some_stuff(current_user.id, 20)For versions 5.0+, you will need to add this line to your initializer to re-enable and get the old behavior: (https://github.com/mperham/sidekiq/blob/master/5.0-Upgrade.md)
Sidekiq::Extensions.enable_delay!- Start sidekiq from the root of your Rails application so the jobs will be processed:
bundle exec sidekiq
That's it. You do not need to turn on thread-safe mode. You probably should tune your Active Record pool size if your workers are using Active Record. See Advanced Options for more detail.
There are some non-Rails examples in examples/. por.rb is a "Plain Old Ruby" example, and sinkiq.rb is a Sinatra integration.
Watch an overview:
Next: The Basics
