Appearance
Setup Background Jobs for your Rails application
Are you using Solid Queue, GoodJob or Sidekiq as your background job backend? This guide will show you how to set it up on Deploio.
Solid Queue is the default Active Job backend since Rails 8. It stores jobs in your existing PostgreSQL database, so you don't need a Redis instance for it.
Setup
Add Solid Queue to your application:
bash
bundle add solid_queue
bin/rails solid_queue:installThis generates a configuration file at config/solid_queue.yml and a database schema file.
Single-database configuration
By default, Solid Queue is configured to use a separate database. On Deploio, this works with a Business database (which gives you a full database server), but not with an Economy database (single database).
To run Solid Queue on your existing primary database:
- Copy the contents of
db/queue_schema.rbinto a new migration:
bash
bin/rails generate migration CreateSolidQueueTablesPaste the table definitions from db/queue_schema.rb into the generated migration file.
- Point Solid Queue to your primary database:
ruby
# config/environments/production.rb
config.solid_queue.connects_to = { database: { writing: :primary } }- Run the migration:
bash
nctl exec app {APP_NAME} -- bundle exec rails db:migrate- Delete
db/queue_schema.rb— it is no longer needed.
Creating the worker
bash
nctl update app {APP_NAME} \
--worker-job-command="bin/jobs" \
--worker-job-name "solid-queue" \
--worker-job-size microObserving a Worker
The worker's logs are aggregated with the application logs. You can view all the logs using the nctl logs command. If you wish to only view the logs for the worker, you can filter the logs using the -t, --type flag:
bash
nctl logs app {APP_NAME} -t worker_jobRemoving a Worker
Should you wish to remove a worker from a running application, you can use the nctl update app command:
bash
nctl update app {APP_NAME} --delete-worker-job={worker_job_name}Next Steps
Do you need to configure Continuous Deployment? Proceed to the next step.