Getting Started - rselk/sidekiq GitHub Wiki
Sidekiq makes every effort to make usage with modern Rails (3.0+) applications as simple as possible.
Rails
- Add sidekiq to your Gemfile:
gem 'sidekiq'
- Add a worker in
app/workers
to process messages asynchronously:
class HardWorker
include Sidekiq::Worker
def perform(name, count)
# do something
end
end
- Send a message to be processed asynchronously:
HardWorker.perform_async('bob', 5)
You can also send messages by calling the delay
method on a class method:
User.delay.do_some_stuff(current_user.id, 20)
- Start sidekiq from the root of your Rails application so the message will be processed:
bundle exec sidekiq
That's it. You do not need to turn on thread-safe mode. You probably should tune your ActiveRecord pool size if your workers are using ActiveRecord. See Advanced Options for more detail.
Plain Ruby
There are some non-Rails examples in examples/
. por.rb
is a "Plain Old Ruby" example, and sinkiq.rb
is a Sinatra integration.
Next: Read Best Practices