Background Jobs
This template uses Solid Queue as its background job backend — the Rails 8 default. Jobs persist to SQLite, in their own queue database (storage/production_queue.sqlite3 beside the app’s storage/production.sqlite3) through Active Record’s multi-DB support.
Design rationale: queue topology decisions on this page came out of an Ops panel review.
Where jobs run
By default — and per the template’s design — Solid Queue runs inside the web server’s Puma process. The SOLID_QUEUE_IN_PUMA: true setting in config/deploy.yml activates Solid Queue’s Puma plugin (plugin :solid_queue in config/puma.rb), which starts the Supervisor as part of Puma’s boot.
This means:
- One container handles HTTP requests and background jobs
- One image deploy updates both
- No accessory networking for the job runner
- No SQLite-can’t-reach-the-other-host problem
It’s the right default for a SQLite + one-VPS template. When it stops being enough, see Move jobs to a dedicated host below.
Named queues (for observability)
config/queue.yml declares three named queues instead of the queues: "*" wildcard:
workers:
- queues: [ mailers, default, low ]
threads: 3
processes: <%= ENV.fetch("JOB_CONCURRENCY", 1) %>
polling_interval: 0.1
Why named queues? With a single worker process + 3 threads sharing the GVL, splitting queues doesn’t relieve contention — that’s a multi-process win, not a multi-queue win. What named queues do give you is observability: when jobs pile up waiting in a queue, you can see which class of work is slow.
| Queue | Convention | Examples |
|---|---|---|
default |
Business logic, model callbacks, the notifier sweeps, anything you perform_later without specifying a queue |
WorkspaceInvitationExpiringSweepJob, WorkspaceCapacitySweepJob, NotificationDispatchReconcileJob, custom callback jobs |
mailers |
Action Mailer / mailer-class jobs (network-bound, slower) | DigestMailerJob, MagicLinkMailer.sign_in_link(...).deliver_later |
low |
Best-effort cleanup and retention sweeps — nobody is waiting on it, and it must never delay work someone is waiting on | clear_solid_queue_finished_jobs, NotificationCleanupJob, ExpiredSessionsSweepJob, WebauthnChallengesSweepJob, UnattachedBlobsSweepJob, ActivityLogRetentionSweepJob |
Routing a job to a specific queue
Set queue_as in the job class:
class DigestMailerJob < ApplicationJob
queue_as :mailers
def perform(...)
# ...
end
end
Or route at perform time:
SomeJob.set(queue: :low).perform_later(arg)
Mailer.deliver_later jobs use the mailers queue (config.action_mailer.deliver_later_queue_name in config/application.rb). The worker claims mailers first, so a sign-in link goes ahead of backups and sweeps.
Recurring jobs
Recurring jobs are declared in config/recurring.yml and dispatched by Solid Queue’s scheduler. The template ships eleven:
| Job | Cadence | Queue | What it does |
|---|---|---|---|
database_backup |
Daily at 2am (BACKUP_SCHEDULE) |
default |
Backs up the app database and uploaded files once a destination is set; see Backups |
clear_solid_queue_finished_jobs |
Every hour at :12 | low |
Cleans up completed/failed jobs from Solid Queue’s own tables in batches with 0.3s sleep between |
workspace_invitation_expiring_sweep |
Every 6 hours | default |
Notifies users whose invitations expire soon (per-day idempotency) |
workspace_capacity_sweep |
Every 12 hours | default |
Alerts workspace owners approaching member limits |
digest_mailer |
Every 15 minutes | mailers |
Polls the digest_next_due_at index to send pending digest emails per each user’s cadence |
notification_dispatch_reconcile |
Every 15 minutes | default |
Re-enqueues Noticed::EventJob for events whose enqueue never landed — rows committed, dispatched_at still NULL between 5 minutes and 24 hours old. On default, not low: it re-delivers a notification a user is waiting on (#927) |
notification_cleanup |
Daily at 3am UTC | low |
Batched deletion of old notifications (chunks of 100 with SQLite lock release between transactions) |
expired_sessions_sweep |
Daily at 4am | low |
Batched delete of sessions past the idle/absolute timeouts (expiry is already enforced at read time) |
webauthn_challenges_sweep |
Daily at 4:30am | low |
Deletes WebAuthn challenge rows past a 1-day grace, consumed or not |
unattached_blobs_sweep |
Daily at 5am | low |
Purges direct-upload blobs that were never attached, after a 2-day grace |
activity_log_retention_sweep |
Weekly, Sunday 3:30am | low |
Bounds the activity trail at the job’s RETENTION_WINDOW, minus the security retention floor |
Why the sweeps are on the low queue
Six of the eleven entries are pure housekeeping — nothing downstream is waiting on them — so they belong on low, where they cannot delay work someone is waiting on. Three stay on default because they put a notification in front of a user: the two workspace_* sweeps dispatch user-facing notifiers, and notification_dispatch_reconcile re-delivers one that already failed to arrive. database_backup is on default too.
A recurring entry with no queue: key is not “the default queue” — Solid Queue resolves it to SolidQueue::RecurringJob, whose queue is solid_queue_recurring. Nothing in config/queue.yml polls that, so such a job enqueues and is never claimed, silently. Always name a queue.
Why digest_mailer is on the mailers queue
It’s the only currently-shipping recurring job that is mailer-class work — network-bound, can be slow due to SMTP timeouts. Routing it to mailers gives you a clean operational signal: when jobs pile up waiting in the mailers queue, you know it’s SMTP, not your sweep jobs.
Adding a recurring job
Append to config/recurring.yml:
production:
my_new_job:
class: MyNewJob
queue: default # or mailers / low
schedule: every 30 minutes
Schedule syntax supports every N seconds/minutes/hours/days, at H:Mam every day, and full cron expressions. See Solid Queue docs for the full schedule grammar.
Mission Control (the job dashboard)
Mission Control isn’t in the template’s Gemfile. Add the mission_control-jobs gem, then in development you can mount the dashboard:
# config/routes.rb
mount MissionControl::Jobs::Engine, at: "/jobs" if Rails.env.development?
In production, mount it behind Pundit authorization so only admins can see it. The dashboard shows per-queue throughput, in-flight jobs, failures, and retries — invaluable for debugging “why is X queue backed up?”
Configuration knobs
| Setting | Default | Where | When to change |
|---|---|---|---|
JOB_CONCURRENCY |
1 |
config/deploy.yml env.clear |
Increase only after migrating off SOLID_QUEUE_IN_PUMA: true — additional processes can’t all run inside Puma |
threads: 3 |
3 | config/queue.yml |
Lower to 2 if you measure SQLite write-lock contention; higher buys little because the GVL serializes Ruby work anyway |
polling_interval: 0.1 |
100ms | config/queue.yml |
Lower = more responsive job pickup, more CPU spent polling. The default is fine for nearly all workloads |
dispatchers.batch_size: 500 |
500 | config/queue.yml |
Tune up if you have huge backlog dispatch storms; rarely needed |
Deploy-time behavior
When kamal deploy rolls a new container:
- Solid Queue’s Puma plugin receives the shutdown signal alongside Puma
- It stops the Supervisor when Puma stops, which begins draining in-flight jobs
- Docker waits
stop_timeoutseconds before SIGKILL (45 inconfig/deploy.yml— see Deployment) - Any job that hasn’t completed by then gets SIGKILLed and re-runs on the next container (via Solid Queue’s at-least-once delivery semantics)
Jobs you write should be idempotent. Solid Queue gives you at-least-once delivery; deploys can SIGKILL mid-execution if stop_timeout is too tight. Use database constraints, idempotency keys, or find_or_create_by! patterns instead of assuming “this job runs exactly once.”
Move jobs to a dedicated host
Move jobs off the in-Puma supervisor when any of these is true:
- Sustained job throughput exceeds ~10 jobs/sec
- You’ve added a second
webhost (which can’t all run separate Solid Queue supervisors against the same SQLite file anyway) - Recurring jobs are noticeably affecting HTTP p99 latency
Then follow the four-step checklist on Deployment. The summary:
- Add a database accessory (Postgres or MySQL)
- Set
DB_HOSTinenv.clear - Flip
SOLID_QUEUE_IN_PUMAtofalse - Uncomment
servers.job:indeploy.ymland deploy a separatebin/jobssupervisor
The same image runs in both web and job roles — only the cmd differs. Mission Control sees both supervisors and aggregates their queue stats.
Local development
Development runs jobs the way production does: config.active_job.queue_adapter = :solid_queue, on the queue database. bin/dev starts the web server, the Tailwind watcher and bin/jobs (from Procfile.dev), so jobs, mail and recurring schedules run while it’s up, and concurrency limits apply as in production.
If you start only bin/rails server, jobs queue up and nothing works them. That includes mail sent with deliver_later. Use bin/dev, or run bin/jobs alongside the server.
Mail sent from a job links to the web server’s port, not the job process’s. Foreman gives each Procfile.dev process its own PORT (3000 for the server, 3200 for bin/jobs), so bin/dev also exports the server’s port as DEV_SERVER_PORT, and development mail links read that first. bin/dev takes the port from -p, then PORT in .env, then PORT in your shell. If you run bin/jobs yourself beside a server on another port, give both the same PORT. bin/rails server -p changes only the server, so prefer PORT=3001 bin/rails server.
Action Cable uses Solid Cable in development too, on its own cable database. A job runs in bin/jobs, a separate process, and Rails’ default async cable adapter only reaches browsers connected to the process that broadcast. With Solid Cable, a job’s Turbo broadcasts reach the page. An existing checkout needs bin/rails db:prepare once to create storage/development_cable.sqlite3.
If you want to test job processing in isolation:
bin/jobs # Runs only the Solid Queue Supervisor, no Puma
Useful when you’re iterating on a job and don’t need web requests in the mix.
A job that emails a workspace’s members
Send it through a notifier, not a mailer of your own. A notifier brings what a hand-written mailer would have to rebuild:
- each member’s notification preferences for the notifier’s category;
- the digest and quiet hours, through
deliver_email_now?; - no email to a suspended user, because
NotificationMailerskips them; - the in-app bell, alongside the email.
WorkspaceCapacitySweepJob and WorkspaceCapacityApproachingNotifier are a
working pair of this shape, sent to a workspace’s owners.
The job takes the workspace’s id, loads it, and hands the workspace to the
notifier. deliver(nil) leaves choosing the recipients to the notifier:
class WorkspaceDigestJob < ApplicationJob
def perform(workspace_id)
workspace = Workspace.kept.find_by(id: workspace_id)
return unless workspace
WorkspaceDigestNotifier.with(record: workspace).deliver(nil)
end
end
The notifier’s recipients block returns the workspace’s kept members.
permitted_in_app drops anyone who turned the category off:
class WorkspaceDigestNotifier < ApplicationNotifier
category :workspace_activity
severity :info
recipients do
permitted_in_app(record.memberships.kept.includes(:user).filter_map(&:user))
end
deliver_by :email do |config|
config.mailer = "NotificationMailer"
config.method = :workspace_digest
config.before_enqueue = -> { throw(:abort) unless deliver_email_now? }
config.enqueue = true
end
notification_methods do
def message
render_safe_or_placeholder do
I18n.t("notifications.workspace_digest.message", locale: recipient_locale,
workspace_name: event.record.name)
end
end
end
end
The email itself is a method on NotificationMailer, with its view and a
subject at notification_mailer.workspace_digest.subject.
Notifier subclasses covers
url, record_preloads and the specs that check them.
This job doesn’t set Current.workspace, because nothing it calls reads it.
Set it, and read it back with Current.workspace!, only when the job calls
something that does, as
Outside the request cycle
explains.
See also
- Deployment — Kamal topology + when to move jobs to their own host
- Notifications — User-facing side of recurring
digest_mailerand friends - Notifications (technical) —
Noticedintegration with Solid Queue config/queue.yml— Worker configuration with inline commentsconfig/recurring.yml— Schedule declarations- Solid Queue GitHub — Upstream docs and schedule syntax reference