Blog · Articles tagged with "redis" · show all articles »

How to make everything background-processable through Sidekiq

I recently switched from Resque to Sidekiq for background processing in a project I'm working on. Sidekiq has a very slick feel to it and is basically a supercharged version of Resque, using threads instead of processed for its workers.

One thing that has irritated me when using Resque was that one was supposed to create separate worker classes for each job that should be processed in the background. While that makes sense for "real" jobs, e.g. syncing the Mailchimp database with your own or exporting some data into a XML file and mailing it out, often I just wanted to make an existing (class or instance) method processable in the background, e.g. user.perform_async :set_timezone_from_ip, request.remote_ip or Account.perform_async :disable_overdue.

Sidekiq offers the delay and delay_for methods to make class and instance method calls asynchronous, as detailed in their Wiki. It also says the following on that Wiki page, though:

I strongly recommend avoid delaying methods on instances. This stores object state in Redis and which can get out of date, causing stale data problems."

Read on