rails-jobs-patterns
Railsでバックグラウンドジョブや非同期処理を行う際に、ジョブキューやSidekiqなどの設定、リトライ処理、ジョブの冪等性確保などを支援し、効率的なジョブ管理を実現するSkill。
📜 元の英語説明(参考)
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", "scheduled job", "cron", "retry", "idempotent".
🇯🇵 日本人クリエイター向け解説
Railsでバックグラウンドジョブや非同期処理を行う際に、ジョブキューやSidekiqなどの設定、リトライ処理、ジョブの冪等性確保などを支援し、効率的なジョブ管理を実現するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o rails-jobs-patterns.zip https://jpskill.com/download/10047.zip && unzip -o rails-jobs-patterns.zip && rm rails-jobs-patterns.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10047.zip -OutFile "$d\rails-jobs-patterns.zip"; Expand-Archive "$d\rails-jobs-patterns.zip" -DestinationPath $d -Force; ri "$d\rails-jobs-patterns.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
rails-jobs-patterns.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
rails-jobs-patternsフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Rails バックグラウンドジョブのパターン
Rails アプリケーションで信頼性が高く、効率的なバックグラウンドジョブを構築するためのパターンです。
このスキルが適用される場合
- ActiveJob を使用したバックグラウンドジョブの作成
- Sidekiq キューとワーカーの設定
- 冪等なジョブパターンの実装
- エラー処理とリトライ戦略
- 大規模なデータセットのバッチ処理
- 定期的なジョブのスケジュール
コア原則
冪等性
ジョブは複数回実行しても安全であるべきです。
def perform(order_id)
order = Order.find(order_id)
return if order.processed? # 再処理に対する保護
order.with_lock do
return if order.processed?
process_order(order)
order.update!(status: 'processed')
end
end
小さく、焦点を絞ったジョブ
- ジョブごとに単一の責任
- オブジェクトではなく ID を渡す (シリアライゼーション)
- ペイロードを最小限に抑える
エラー処理
- 一時的なエラーには
retry_onを使用する - 永続的なエラーには
discard_onを使用する - コンテキストとともにエラーをログに記録する
クイックリファレンス
| パターン | 使用する場合 |
|---|---|
retry_on |
一時的なエラー (ネットワーク、タイムアウト) |
discard_on |
永続的なエラー (レコードが削除された) |
with_lock |
並行実行の防止 |
| バッチ処理 | 大規模なデータセット |
| 結果の追跡 | ジョブのステータスレポート |
詳細なドキュメント
- patterns.md - 例を含む完全なジョブパターン
基本的なジョブ構造
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
キューの設定
# config/sidekiq.yml
:queues:
- [critical, 6]
- [default, 3]
- [low, 1]
ジョブのテスト
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 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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