Delegate independent tasks to specialized agents working concurrently with isolated context.
Rails Background Job Patterns
rails-jobs-patterns
ActiveJob and background processing patterns for Rails. Automatically invoked when working with background jobs, Sidekiq, async processing, job queues, scheduling, or the app/jobs directory. Triggers on "job", "background job", "ActiveJob", "Sidekiq", "async", "queue", "perform_later", "worker", ...
SKILL.md
Full skill instructions
Rails Background Job Patterns
Patterns for building reliable, efficient background jobs in Rails applications.
When This Skill Applies
- Creating background jobs with ActiveJob
- Configuring Sidekiq queues and workers
- Implementing idempotent job patterns
- Error handling and retry strategies
- Batch processing large datasets
- Scheduling recurring jobs
Core Principles
Idempotency
Jobs should be safe to run multiple times:
def perform(order_id)
order = Order.find(order_id)
return if order.processed? # Guard against re-processing
order.with_lock do
return if order.processed?
process_order(order)
order.update!(status: 'processed')
end
end
Small, Focused Jobs
- Single responsibility per job
- Pass IDs, not objects (serialization)
- Keep payloads minimal
Error Handling
- Use
retry_onfor transient failures - Use
discard_onfor permanent failures - Log errors with context
Quick Reference
| Pattern | Use When |
|---|---|
retry_on | Transient errors (network, timeout) |
discard_on | Permanent failures (record deleted) |
with_lock | Preventing concurrent execution |
| Batch processing | Large datasets |
| Result tracking | Job status reporting |
Detailed Documentation
- patterns.md - Complete job patterns with examples
Basic Job Structure
class ProcessOrderJob < ApplicationJob
queue_as :default
retry_on ActiveRecord::RecordNotFound, wait: 5.seconds, attempts: 3
discard_on ActiveJob::DeserializationError
def perform(order_id)
order = Order.find(order_id)
OrderProcessor.new(order).process!
end
end
Queue Configuration
# config/sidekiq.yml
:queues:
- [critical, 6]
- [default, 3]
- [low, 1]
Testing Jobs
RSpec.describe ProcessOrderJob, type: :job do
include ActiveJob::TestHelper
it 'processes the order' do
order = create(:order)
expect {
ProcessOrderJob.perform_now(order.id)
}.to change { order.reload.status }.from('pending').to('processed')
end
it 'enqueues in the correct queue' do
expect {
ProcessOrderJob.perform_later(1)
}.to have_enqueued_job.on_queue('default')
end
end
More Other skills
brand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.
internal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).
Fundamental design principles for writing maintainable, testable Python code.
responsive-design
Modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first strategies.
Generate Playwright tests from scenarios using interactive browser exploration and validation.
Automated website exploration and test case generation using Playwright.
Modern React state management with Redux Toolkit, Zustand, Jotai, and React Query for every state category.
gdpr-data-handling
GDPR-compliant data handling with consent management, data subject rights, and privacy controls.
Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.
refactor-plan
Detailed multi-file refactor planning with safety checks and rollback guidance.
