# Resque — Redis-Backed Background Jobs for Ruby > Mature Ruby library for creating, queuing, and processing background jobs using Redis, originally built at GitHub. ## Install Save in your project root: # Resque — Redis-Backed Background Jobs for Ruby ## Quick Use ```ruby # app/jobs/image_resize_job.rb class ImageResizeJob @queue = :images def self.perform(image_id) Image.find(image_id).resize! end end Resque.enqueue(ImageResizeJob, 42) ``` ```bash QUEUE=images rake resque:work ``` ## Introduction Resque is a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later with dedicated worker processes. Originally built at GitHub to handle tasks like repository forking, page rendering, and email delivery, it became one of the foundational tools for asynchronous processing in the Ruby ecosystem. Jobs are stored as simple JSON in Redis, making the system inspectable and debuggable. ## What Resque Does - Queues background jobs as JSON payloads in Redis lists - Processes jobs with forking workers that isolate each job in a child process - Provides a built-in Sinatra web UI for monitoring queues, workers, and failed jobs - Supports multiple named queues with configurable priority ordering - Offers retry, scheduling, and rate-limiting through a plugin ecosystem ## Architecture Overview Resque stores each job as a JSON hash containing the class name and arguments in a Redis list keyed by queue name. Workers poll one or more queues, dequeue a job, fork a child process, and execute the job's `perform` class method. Forking ensures that memory leaks or crashes in a job do not affect the long-running worker process. The web dashboard reads Redis directly to display real-time queue depths, worker status, and failed job details. ## Self-Hosting & Configuration - Add `gem 'resque'` to your Gemfile and run `bundle install` - Configure the Redis connection via `Resque.redis = 'redis://localhost:6379'` - Define job classes with a `@queue` attribute and a `self.perform` method - Start workers with `QUEUE=critical,default rake resque:work` - Mount the web UI in your Rails routes: `mount Resque::Server, at: '/resque'` ## Key Features - Jobs are simple Ruby classes with no framework lock-in - Forking worker model provides memory isolation per job - Built-in web dashboard for real-time monitoring - JSON-based job format is easy to inspect and debug in Redis - Extensive plugin ecosystem for scheduling, retries, and batching ## Comparison with Similar Tools - **Sidekiq** — threaded workers with higher throughput; Resque uses forking for stronger isolation - **Delayed Job** — stores jobs in the database; Resque uses Redis for speed - **GoodJob** — Postgres-backed with Active Job; Resque predates Active Job - **Celery** — Python equivalent with similar Redis/AMQP backends - **BullMQ** — Node.js queue; Resque serves the Ruby ecosystem ## FAQ **Q: Should I choose Resque or Sidekiq for a new project?** A: Sidekiq offers higher throughput with threads. Resque is a good fit when you need forking isolation or prefer a simpler mental model. **Q: How do I handle failed jobs?** A: Resque stores failed jobs in a dedicated Redis key. The web UI lets you inspect, retry, or clear them. **Q: Can Resque work with Rails Active Job?** A: Yes. Set `config.active_job.queue_adapter = :resque` in your Rails configuration. **Q: How do I schedule recurring jobs?** A: Use the `resque-scheduler` gem, which adds cron-like scheduling backed by Redis. ## Sources - https://github.com/resque/resque - https://github.com/resque/resque/wiki --- Source: https://tokrepo.com/en/workflows/asset-32d7f6db Author: AI Open Source