$npx -y skills add ThibautBaissac/rails_ai_agents --skill solid-queue-setupConfigures Solid Queue for background jobs in Rails 8. Use when setting up background processing, creating background jobs, configuring job queues, or migrating from Sidekiq to Solid Queue. WHEN NOT: Synchronous in-request processing, real-time WebSocket features (use Action Cabl
| 1 | # Solid Queue Setup for Rails 8 |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Solid Queue is Rails 8's default Active Job backend: |
| 6 | - Database-backed (no Redis required) |
| 7 | - Built-in concurrency controls |
| 8 | - Supports priorities and multiple queues |
| 9 | - Mission-critical job processing |
| 10 | - Web UI available via Mission Control |
| 11 | |
| 12 | ## Quick Start |
| 13 | |
| 14 | ### Installation |
| 15 | |
| 16 | ```bash |
| 17 | # Add to Gemfile (included in Rails 8 by default) |
| 18 | bundle add solid_queue |
| 19 | |
| 20 | # Install Solid Queue |
| 21 | bin/rails solid_queue:install |
| 22 | |
| 23 | # Run migrations |
| 24 | bin/rails db:migrate |
| 25 | ``` |
| 26 | |
| 27 | ### Configuration |
| 28 | |
| 29 | ```yaml |
| 30 | # config/solid_queue.yml |
| 31 | default: &default |
| 32 | dispatchers: |
| 33 | - polling_interval: 1 |
| 34 | batch_size: 500 |
| 35 | workers: |
| 36 | - queues: "*" |
| 37 | threads: 3 |
| 38 | processes: 1 |
| 39 | polling_interval: 0.1 |
| 40 | |
| 41 | development: |
| 42 | <<: *default |
| 43 | |
| 44 | production: |
| 45 | <<: *default |
| 46 | workers: |
| 47 | - queues: [critical, default] |
| 48 | threads: 5 |
| 49 | processes: 2 |
| 50 | - queues: [low] |
| 51 | threads: 2 |
| 52 | processes: 1 |
| 53 | ``` |
| 54 | |
| 55 | ### Set as Active Job Adapter |
| 56 | |
| 57 | ```ruby |
| 58 | # config/application.rb |
| 59 | config.active_job.queue_adapter = :solid_queue |
| 60 | |
| 61 | # Or per environment |
| 62 | # config/environments/production.rb |
| 63 | config.active_job.queue_adapter = :solid_queue |
| 64 | ``` |
| 65 | |
| 66 | ## Workflow Checklist |
| 67 | |
| 68 | ``` |
| 69 | Solid Queue Setup: |
| 70 | - [ ] Add solid_queue gem |
| 71 | - [ ] Run solid_queue:install |
| 72 | - [ ] Run migrations |
| 73 | - [ ] Configure queues in solid_queue.yml |
| 74 | - [ ] Set queue adapter in config |
| 75 | - [ ] Create first job with spec |
| 76 | - [ ] Test job execution |
| 77 | - [ ] Configure recurring jobs (if needed) |
| 78 | ``` |
| 79 | |
| 80 | ## Creating Jobs |
| 81 | |
| 82 | ### Basic Job |
| 83 | |
| 84 | ```ruby |
| 85 | # app/jobs/send_welcome_email_job.rb |
| 86 | class SendWelcomeEmailJob < ApplicationJob |
| 87 | queue_as :default |
| 88 | |
| 89 | def perform(user_id) |
| 90 | user = User.find(user_id) |
| 91 | UserMailer.welcome(user).deliver_now |
| 92 | end |
| 93 | end |
| 94 | ``` |
| 95 | |
| 96 | ### Job with Retries |
| 97 | |
| 98 | ```ruby |
| 99 | # app/jobs/process_payment_job.rb |
| 100 | class ProcessPaymentJob < ApplicationJob |
| 101 | queue_as :critical |
| 102 | |
| 103 | # Retry on specific errors |
| 104 | retry_on PaymentGatewayError, wait: :polynomially_longer, attempts: 5 |
| 105 | |
| 106 | # Don't retry on these |
| 107 | discard_on ActiveRecord::RecordNotFound |
| 108 | |
| 109 | # Custom error handling |
| 110 | rescue_from(StandardError) do |exception| |
| 111 | ErrorNotifier.notify(exception) |
| 112 | raise # Re-raise to trigger retry |
| 113 | end |
| 114 | |
| 115 | def perform(order_id) |
| 116 | order = Order.find(order_id) |
| 117 | PaymentService.new.charge(order) |
| 118 | end |
| 119 | end |
| 120 | ``` |
| 121 | |
| 122 | ### Job with Priority |
| 123 | |
| 124 | ```ruby |
| 125 | class UrgentNotificationJob < ApplicationJob |
| 126 | queue_as :critical |
| 127 | |
| 128 | # Lower number = higher priority |
| 129 | # Default is 0 |
| 130 | def priority |
| 131 | -10 |
| 132 | end |
| 133 | |
| 134 | def perform(notification_id) |
| 135 | # Process urgent notification |
| 136 | end |
| 137 | end |
| 138 | ``` |
| 139 | |
| 140 | ## Enqueueing Jobs |
| 141 | |
| 142 | ```ruby |
| 143 | # Enqueue immediately |
| 144 | SendWelcomeEmailJob.perform_later(user.id) |
| 145 | |
| 146 | # Enqueue with delay |
| 147 | SendReminderJob.set(wait: 1.hour).perform_later(user.id) |
| 148 | |
| 149 | # Enqueue at specific time |
| 150 | SendReportJob.set(wait_until: Date.tomorrow.noon).perform_later |
| 151 | |
| 152 | # Enqueue on specific queue |
| 153 | ProcessJob.set(queue: :low).perform_later(data) |
| 154 | |
| 155 | # Perform immediately (skips queue - use sparingly) |
| 156 | SendWelcomeEmailJob.perform_now(user.id) |
| 157 | ``` |
| 158 | |
| 159 | ## Recurring Jobs |
| 160 | |
| 161 | ```yaml |
| 162 | # config/recurring.yml |
| 163 | production: |
| 164 | daily_report: |
| 165 | class: GenerateDailyReportJob |
| 166 | schedule: every day at 6am |
| 167 | queue: low |
| 168 | |
| 169 | cleanup: |
| 170 | class: CleanupOldRecordsJob |
| 171 | schedule: every sunday at 2am |
| 172 | |
| 173 | sync: |
| 174 | class: SyncExternalDataJob |
| 175 | schedule: every 15 minutes |
| 176 | ``` |
| 177 | |
| 178 | ## Testing Jobs |
| 179 | |
| 180 | ### Job Spec Template |
| 181 | |
| 182 | ```ruby |
| 183 | # spec/jobs/send_welcome_email_job_spec.rb |
| 184 | require 'rails_helper' |
| 185 | |
| 186 | RSpec.describe SendWelcomeEmailJob, type: :job do |
| 187 | let(:user) { create(:user) } |
| 188 | |
| 189 | describe '#perform' do |
| 190 | it 'sends welcome email' do |
| 191 | expect { |
| 192 | described_class.perform_now(user.id) |
| 193 | }.to have_enqueued_mail(UserMailer, :welcome) |
| 194 | end |
| 195 | end |
| 196 | |
| 197 | describe 'enqueueing' do |
| 198 | it 'enqueues the job' do |
| 199 | expect { |
| 200 | described_class.perform_later(user.id) |
| 201 | }.to have_enqueued_job(described_class) |
| 202 | .with(user.id) |
| 203 | .on_queue('default') |
| 204 | end |
| 205 | end |
| 206 | |
| 207 | describe 'retry behavior' do |
| 208 | it 'retries on PaymentGatewayError' do |
| 209 | expect(described_class).to have_retry_on(PaymentGatewayError) |
| 210 | end |
| 211 | end |
| 212 | end |
| 213 | ``` |
| 214 | |
| 215 | ### Test Helpers |
| 216 | |
| 217 | ```ruby |
| 218 | # spec/rails_helper.rb |
| 219 | RSpec.configure do |config| |
| 220 | config.include ActiveJob::TestHelper |
| 221 | end |
| 222 | |
| 223 | # In specs |
| 224 | it 'processes all jobs' do |
| 225 | perform_enqueued_jobs do |
| 226 | UserSignupService.call(user_params) |
| 227 | end |
| 228 | expect(user.reload.welcome_email_sent?).to be true |
| 229 | end |
| 230 | |
| 231 | it 'enqueues multiple jobs' do |
| 232 | expect { |
| 233 | BatchProcessor.process(items) |
| 234 | }.to have_enqueued_job(ProcessItemJob).exactly(items.count).times |
| 235 | end |
| 236 | ``` |
| 237 | |
| 238 | ## Running Solid Queue |
| 239 | |
| 240 | ```bash |
| 241 | # Development (r |