I first encountered the "solid queue" gem when it was announced to be shipped with Rails 8 as the default active job backend.

It is DB-based and compatible with Rails multi-threading. The debugging of active job issues is simpler with its enhanced logging and queue data persisted in the database.

Since Rails 8 is currently under development, I decided to try it with a Rails 7 application.

Setup

It is plug-and-play, with 3 simple steps below.

  1. Install the gem

    gem "solid_queue"
    
  2. Install and run its migration

    $ rails solid_queue:install:migrations
    $ rails db:migrate
    
  3. Update queue adapter in configuration

    config.active_job.queue_adapter = :solid_queue
    
  4. To test it, you can run this command

    $ bundle exec rake solid_queue:start
    

Using it in Production

  1. There are many ways to manage the solid queue processes. I choose to use supervisor on a Ubuntu server.

    $ sudo apt update && sudo apt install supervisor
    
  2. This can be done by creating a configuration file

    $ sudo pico /etc/supervisor/conf.d/rails-solid-queue.conf
    
    [program:rails-solid-queue]
    process_name=%(program_name)s_%(process_num)02d
    directory=/path/to/app
    command=/path/to/bundle exec rake solid_queue:start
    environment=RAILS_ENV=production
    autostart=true
    autorestart=true
    stopasgroup=true
    killasgroup=true
    user=user
    numprocs=1
    redirect_stderr=true
    stdout_logfile=/path/to/log
    stopwaitsecs=3600
    
  3. Then load and start the configuration

    $ sudo supervisorctl reread
    $ sudo supervisorctl update
    

Integrate it with the Capistrano deployment

  1. I use Capistrano to deploy the demo app. So the supervisor-monitored processes must be restarted when I deploy new codes.

  2. The following codes are added in my deploy.rb to perform the restart after the deployment.

    # etc
    
    # restart supervisor
    namespace :deploy do
      desc 'Restart supervisor rails-solid-queue'
      task :restart_application do
        on roles(:app) do
          execute :sudo, 'supervisorctl restart rails-solid-queue:*'
        end
      end
    
      after :finished, :restart_application
    end
    
  3. That is all the setup needed to deploy Solid Queue in production.