Jonathan Bennett

Rails background jobs with Solid Queue

I made an app to help track my kids’ chores and responsibilities (yes, I am that kind of dad). We’ve got an old iPad mounted in the kitchen that stays on a dashboard screen, showing outstanding tasks and reminders.

One of my favourite features is the weekly schedule builder. My wife and I can quickly create recurring chores—but those tasks don’t get created automatically. Some pages in the app create missing tasks on page load, which was easy to implement at first. But since the dashboard uses Turbo Streams and doesn’t refresh constantly, it’s usually out of date by morning.

I always intended to generate tasks in the background. So let’s walk through setting that up using Solid Queue.

Step 1: Install Solid Queue

Add the gem and install it:

bundle add solid_queue
bin/rails solid_queue:install

Step 2: Configure database.yml

I’m using Postgres in both development and production, so I had to add an extra database connection for Solid Queue.

Also, I needed to move the main connection under a primary key:

development:
  primary:
    <<: *default
    database: irl_game_development
  queue:
    <<: *default
    database: irl_game_development_queue
    migrations_paths: db/queue_migrate

production:
  primary:
    <<: *default
    url: <%= ENV["DATABASE_URL"] %>
  queue:
    <<: *default
	# this will be based on your environment
    url: <%= ENV["RED_DATABASE_URL"] %> 
    migrations_paths: db/queue_migrate

Step 3: Enable Solid Queue in Puma (Development Only)

Solid Queue needs a separate process to run jobs. You can do this by setting SOLID_QUEUE_IN_PUMA in your environment or your Procfile.dev, but I just hardcoded it to run in development:

# config/puma.rb
plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"] || Rails.env.development?

Step 4: Enable Solid Queue in Development Config

By default, solid_queue:install enables it only in production. I want to use it in development too:

# config/environments/development.rb
Rails.application.configure do
  # ...
  config.active_job.queue_adapter = :solid_queue
  config.solid_queue.connects_to = {
	database: { writing: :queue }
  }
  # ...
end

That :queue reference matches the queue block in database.yml—it tells Solid Queue where to store job data.

Step 5: Run Jobs in Production

Finally, I configured my production system (I use Hatchbox) to run Solid Queue as a separate process. I just added a process that runs:

bin/jobs

Now that background jobs are up and running, we’re ready to use them to create scheduled tasks automatically.

But that’ll have to wait for the next post—this one’s long enough already.