rails-jobs

Design thin Rails background jobs with Sidekiq and ActiveJob error handling.

2|Updated May 15, 2015
One-click install
npx skills add https://github.com/stephendolan/dotfiles --skill rails-jobs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-jobs
Source: https://github.com/stephendolan/dotfiles/tree/main/claude/skills/rails-jobs
Command: npx skills add https://github.com/stephendolan/dotfiles --skill rails-jobs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps teams design background jobs that are small, explicit, and easy to test, with clear error handling and delegation to domain models.

Core Features & Use Cases

  • Thin Jobs: Keep business logic in models/services, not in the job.
  • Error Handling: Use discard/retry strategies to handle transient vs permanent failures.
  • Naming & Organization: Clear job naming and proper namespacing for maintainability.

Quick Start

Show an example of a SimpleJob enqueuing a background task with proper error handling.

Frequently Asked Questions about rails-jobs

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors and retries in Rails background jobs?

Use ActiveJob's `retry_on` and `discard_on` methods to distinguish transient failures from permanent ones. `retry_on` automatically reschedules failed jobs with exponential backoff, while `discard_on` silently drops jobs that encounter permanent errors, keeping your queue clean and reliable.

What's the best way to structure Rails background jobs with Sidekiq?

Keep jobs thin by delegating business logic to models and services. Jobs should only handle enqueuing, argument deserialization, and calling domain methods. This separation makes jobs testable, reusable, and easier to maintain across your Rails application.

Why do Rails background jobs fail with serialization errors?

ActiveJob and Sidekiq serialize job arguments to JSON, which doesn't support all Ruby types. Pass primitive values, hashes, and IDs instead of full objects. Fetch records inside the job by ID to avoid serialization issues and handle missing records gracefully.

Can I use ActiveJob with Sidekiq for reliable job processing?

Yes. ActiveJob abstracts job queuing, and Sidekiq provides the reliable backend. Together they enable error handling through `retry_on` and `discard_on`, proper job naming conventions, and idempotent job design for safe retries.

How do I make Rails jobs idempotent and safe to retry?

Design jobs to produce the same result when run multiple times with identical arguments. Avoid side effects outside database transactions, check for existing records before creating them, and use conditional logic so repeated executions don't cause duplicates or inconsistencies.

What's the difference between enqueuing jobs now versus later in Rails?

Use `perform_now` for synchronous execution during tests or special cases, and `perform_later` for background processing. Clear naming with `_now` and `_later` semantics makes intent explicit, improves debugging, and helps teams understand when work happens asynchronously versus immediately.