Using Solid Queue to Handle Background Tasks
What is Solid Queue?
Solid Queue is the default background job processing library for Rails 8. It uses your database (PostgreSQL®, MySQL®, or SQLite) to manage the job queue, eliminating the need for a separate Redis® OSS instance for many use cases.
Configuration for Rails 8
When using Solid Queue on Scalingo, you need to ensure that your database configuration in config/database.yml correctly references the DATABASE_URL environment variable for both the primary database and the queue database.
By default, Rails 8 might expect a separate database for the queue, but on Scalingo, you typically use the same database for both.
Update your config/database.yml:
production:
primary: &default
adapter: postgresql # or mysql2 (the adapter name for MySQL)
encoding: unicode
url: <%= ENV['DATABASE_URL'] %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
queue:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
Adding “worker” container type in your Procfile
To process background jobs, you need to run the Solid Queue worker process. Add the following line to your Procfile:
worker: bin/jobs
Deployment
After updating your config/database.yml and Procfile, deploy your application:
git add config/database.yml Procfile
git commit -m "Configure Solid Queue for Scalingo"
git push scalingo master
Once deployed, you need to scale the worker container to at least 1 to start processing jobs:
scalingo --app my-app scale worker:1