Moving Code to a Sidekiq Job

A common use of Sidekiq jobs is to move long-running code out of the web request/response cycle and into a background job to free up web server resources to handle other requests. This often means that the user can get a response much more quickly since they won’t have to wait for the slow code from, say, the payments service, to complete. Let’s move all three HTTP calls out of the main request/response path and into a Sidekiq job.

Create a New Sidekiq Job

The example app’s order creation logic makes calls to payments, email, and order fulfillment services over HTTP. If these were real services provided by third parties, the order creation feature would be very slow, and our app’s web servers would spend a lot of ...

Get Ruby on Rails Background Jobs with Sidekiq now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.