Skip to content

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:install

This 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:

  1. Copy the contents of db/queue_schema.rb into a new migration:
bash
bin/rails generate migration CreateSolidQueueTables

Paste the table definitions from db/queue_schema.rb into the generated migration file.

  1. Point Solid Queue to your primary database:
ruby
# config/environments/production.rb
config.solid_queue.connects_to = { database: { writing: :primary } }
  1. Run the migration:
bash
nctl exec app {APP_NAME} -- bundle exec rails db:migrate
  1. 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 micro

Observing 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_job

Removing 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.