Set up background jobs with Sidekiq
✓Works with OpenClaudeYou are a Rails developer. The user wants to set up and configure Sidekiq for background job processing in a Rails application.
What to check first
- Run
bundle list | grep sidekiqto verify Sidekiq gem is installed - Check
config/sidekiq.ymlexists or needs to be created - Verify Redis is running:
redis-cli pingshould returnPONG
Steps
- Add
gem 'sidekiq'to your Gemfile and runbundle install - Create
config/sidekiq.ymlwith concurrency and queue settings - Create a job class in
app/jobs/usingrails generate job JobName - Define the
performmethod in your job class with actual work logic - Enqueue the job using
JobName.perform_later(args)orJobName.set(wait: time).perform_later(args) - Configure
config/initializers/sidekiq.rbto set Redis connection and middleware - Start Sidekiq with
bundle exec sidekiq -c 5 -v(runs 5 concurrent workers) - Monitor jobs using Sidekiq Web UI at
/sidekiqafter mounting in routes
Code
# Gemfile
gem 'sidekiq', '~> 7.0'
gem 'sidekiq-cron', '~> 1.8' # for scheduled jobs
# config/sidekiq.yml
---
:concurrency: 5
:timeout: 25
:verbose: false
:queues:
- [critical, 3]
- [default, 2]
- [low, 1]
# config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
config.redis = { url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/1') }
config.server_middleware do |chain|
chain.add SidekiqMiddleware
end
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/1') }
end
# app/jobs/send_email_job.rb
class SendEmailJob
include Sidekiq::Job
sidekiq_options retry: 5, dead: true
sidekiq_retry_in { |count| count * 60 + rand(30) }
sidekiq_options queue: 'critical'
def perform(user_id, email_type)
user = User.find(user_id)
MailerService.send_email(user, email_type)
end
end
# Usage in controller or model
class PostsController < ApplicationController
def create
@post = Post.create(post_params)
SendEmailJob.perform_later(@post.user_
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Ruby on Rails Skills
Other Claude Code skills in the same category — free to download.
Rails Setup
Scaffold Ruby on Rails app with models and controllers
Rails Active Record
Write Active Record models with associations and validations
Rails API
Build Rails API-only application with serializers
Rails Testing
Write RSpec tests with factories and mocks
Rails Stimulus
Build interactive UIs with Hotwire and Stimulus
Rails ActiveRecord Performance Optimization
Fix N+1 queries, slow scopes, and ActiveRecord pitfalls in production Rails apps
Rails Action Cable WebSockets
Build real-time features in Rails using Action Cable WebSockets
Want a Ruby on Rails skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.