← ClaudeAtlas

rails-jobslisted

Use when writing background jobs with Solid Queue, including recurring jobs and context serialization
mickzijdel/rails-toolkit · ★ 0 · AI & Automation · score 70
Install: claude install-skill mickzijdel/rails-toolkit
# Rails Background Jobs ## Pattern 1: Shallow Job Classes The job is just a conduit for async execution; the logic lives in a model method. ```ruby # app/jobs/webhook/delivery_job.rb class Webhook::DeliveryJob < ApplicationJob queue_as :webhooks def perform(delivery) delivery.deliver end end ``` ```ruby # app/models/webhook/delivery.rb class Webhook::Delivery < ApplicationRecord after_create_commit :deliver_later def deliver_later Webhook::DeliveryJob.perform_later(self) end def deliver in_progress! self.request[:headers] = headers self.response = perform_request self.state = :completed save! webhook.delinquency_tracker.record_delivery_of(self) rescue errored! raise end end ``` --- ## Pattern 2: Account Context Serialization In multi-tenant apps, a module prepended to `ActiveJob::Base` captures `Current.account` at enqueue time, serializes it as a GlobalID, and restores it around `perform` — every job gets tenant context with no manual passing. Full implementation: [[rails-multi-tenancy]] Pattern 5. --- ## Pattern 3: `*_later` / `*_now` Method Convention `_later` suffix for methods that enqueue a job; `_now` suffix for the synchronous version when a class has both. ```ruby # app/models/account/export.rb class Account::Export < ApplicationRecord def build_later ExportAccountDataJob.perform_later(self) end def build processing! zipfile = generate_zip file.attach io: File.open(zipfile.