rails-active-job
3
总安装量
3
周安装量
#59995
全站排名
安装命令
npx skills add https://github.com/shivamsinghchahar/rails-skills --skill rails-active-job
Agent 安装分布
amp
3
gemini-cli
3
github-copilot
3
codex
3
cursor
3
opencode
3
Skill 文档
Active Job: Background Job Processing
Active Job is Rails’ framework for declaring background jobs and processing them asynchronously. Use it to offload work from the request-response cycle, improving application responsiveness.
When to Use Active Jobs
- Email sending: Async mailers to avoid request delays
- Heavy computations: Process data without blocking users
- External API calls: Retry logic for unreliable services
- Bulk operations: Process large datasets in the background
- Scheduled tasks: Recurring operations with cron jobs
- Event processing: Handle webhooks and event notifications
- Cleanup tasks: Database maintenance and data archival
Quick Start
Create a Job
rails generate job SendWelcomeEmail
Define the Job
class SendWelcomeEmailJob < ApplicationJob
queue_as :default # Route to 'default' queue
def perform(user_id)
user = User.find(user_id)
UserMailer.welcome(user).deliver_later
end
end
Enqueue the Job
# Enqueue immediately
SendWelcomeEmailJob.perform_later(user.id)
# Enqueue with delay
SendWelcomeEmailJob.set(wait: 1.hour).perform_later(user.id)
# Enqueue at specific time
SendWelcomeEmailJob.set(wait_until: 2.days.from_now).perform_later(user.id)
# Enqueue multiple jobs at once
user_ids.map { |id| [id] }.then do |args|
SendWelcomeEmailJob.perform_all_later(args)
end
Job Basics
Learn fundamental job concepts and lifecycle:
- Job Definition â Job structure, configuration, perform method
- Job Lifecycle â Job execution phases and callbacks
- Job Patterns â Common implementations and best practices
Queue Management
Configure and manage job queues:
- Queue Setup â Solid Queue configuration, threading, queue ordering
- Concurrency Controls â Limit concurrent job execution
Advanced Features
Master sophisticated job patterns:
- Scheduling & Retries â Recurring jobs, retry strategies, backoff
- Error Handling â Exception handling, discard policies, dead letter queues
- Job Continuations â Multi-step resumable workflows (Rails 8+)
- Bulk Enqueuing â Efficient batch job enqueueing
- Testing â Test job enqueuing and execution
Examples
See Real-world implementations covering:
- Email notifications
- Data imports and exports
- Image processing
- External API synchronization
- Report generation
- Webhook handling
Default Backend: Solid Queue
Rails 8+ includes Solid Queue as the default job backend. Configure in config/solid_queue.yml:
production:
queues:
- name: default
threads: 5
- name: critical
threads: 2
- name: batch
threads: 1
workers:
- name: worker_1
queues: [ default, critical, batch ]
scheduler:
workers: 1
Solid Queue provides:
- Database-backed job storage (no additional dependencies)
- Queue ordering and priority
- Concurrency limiting
- Repeating jobs (cron-like scheduling)
- Multi-threaded workers
- Built-in error tracking
Key Concepts
| Concept | Description |
|---|---|
| Job | Ruby class defining async work (inherits from ApplicationJob) |
| Queue | Named container for jobs (default, critical, batch, etc.) |
| Enqueue | Add job to queue for processing (perform_later) |
| Worker | Process that executes jobs from queues |
| Retry | Automatic job re-execution after failure |
| Discard | Permanently skip job after error |
| Continuation | Resume job execution in steps (Rails 8+) |
Next Steps
- Start with Job Definition to understand job structure
- Configure Queue Setup for your environment
- Add Error Handling for reliability
- Learn Testing strategies for your jobs
- Explore Examples for your use case