-
Notifications
You must be signed in to change notification settings - Fork 11
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/workers
to process jobs asynchronously:
Run this command in your shell:
rails generate sidekiq:worker hard
class HardWorker
include Sidekiq::Worker
def perform(name, count)
# do something
end
end
Your perform
method arguments must be simple, basic types like String, integer, boolean that are supported by JSON. Complex Ruby objects will not work.
To namespace your hard
worker in a rock
namespace:
rails generate sidekiq:worker rock/hard
This will generate the following:
class Rock::HardWorker
include Sidekiq::Worker
def perform(*args)
# 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)
HardWorker.perform_at(5.minutes.from_now, 'bob', 5)
Note: The 5.minutes.from_now
syntax is Rails specific. If you are not using Rails, use unix epoch thus:
HardWorker.perform_at(Time.now+5*60, 'bob', 5)
- Start sidekiq from the root of your Rails application so the jobs will be processed:
bundle exec sidekiq
That's it.
por.rb
in examples/
is a "Plain Old Ruby" example.
Watch an overview:
Next: The Basics
Home | The Basics | Best Practices | Using Redis | Error Handling | Advanced Options | Problems?
This wiki is tracked by git and publicly editable. You are welcome to fix errors and typos. Any defacing or vandalism of content will result in your changes being reverted and you being blocked.