Join GitHub today
Sidekiq is a framework for background job processing. It allows you to scale your application by performing work in the background. This requires three parts:
The Sidekiq client runs in any Ruby process (typically a puma or passenger process) and allows you to create jobs for processing later. There are two ways to create a job in your application code:
MyWorker.perform_async(1, 2, 3) Sidekiq::Client.push('class' => MyWorker, 'args' => [1, 2, 3]) # Lower-level generic API
These two methods are equivalent and create a Hash which represents the job, serializes that Hash to a JSON string and pushes that String into a queue in Redis. This means the arguments to your worker must be simple JSON datatypes (numbers, strings, boolean, array, hash). Complex Ruby objects (e.g. Date, Time, ActiveRecord models) will not serialize properly.
Redis provides data storage for Sidekiq. It holds all the job data along with runtime and historical data to power Sidekiq's Web UI.
See Using Redis for info about connecting to Redis.
Each Sidekiq server process pulls jobs from the queue in Redis and processes them. Like your web processes, Sidekiq boots Rails so your jobs and workers have the full Rails API, including Active Record, available for use. The server will instantiate the worker and call
perform with the given arguments. Everything else is up to your code.