From 6662d7b36cc321f175772fa5101d3bcdb7de9288 Mon Sep 17 00:00:00 2001 From: Brice TEXIER Date: Mon, 9 Nov 2026 11:33:57 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9marrer=20Solid=20Queue=20avec=20bin/jobs?= =?UTF-8?q?=20et=20supprimer=20solid=5Fqueue:quiet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revue d'alignement avec Solid Queue 1.7.2 : - son README ne documente que bin/jobs pour démarrer ; l'unité lance maintenant « exec bin/jobs » au lieu de « rake solid_queue:start ». Vérifié sur une application Rails 8.1 générée avec Solid Queue 1.7.2 : bin/jobs démarre le superviseur en mode fork dans le processus lancé (même PID), s'arrête proprement sur TERM avec le code 0, et tourne sous le Ruby d'asdf avec PATH=/usr/bin:/bin ; - Solid Queue n'a pas de mode quiet : SIGTERM y déclenche un arrêt propre, et en mode async un arrêt qui dépasse shutdown_timeout finit par exit! (code 1), que Restart=on-failure relance. La tâche quiet, qu'aucun hook n'appelle plus, est supprimée. Le test de quiet en mode :system, qui vérifiait la transmission de raise_on_non_zero_exit à sudo, devient un test de status en mode :system ; - README : l'application doit avoir bin/jobs, le gem ne sert pas si Solid Queue tourne dans Puma avec son plugin, et les options de bin/jobs se passent par les variables SOLID_QUEUE_*. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ README.md | 9 ++++++++- lib/capistrano/tasks/solid_queue.rake | 7 ------- .../templates/solid_queue.service.erb | 2 +- test/capistrano/test_service_unit.rb | 4 ++++ test/capistrano/test_systemctl_failure.rb | 19 ++++++------------- test/capistrano/test_tasks.rb | 3 ++- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2195d26..e72f439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - Deploys no longer run `solid_queue:quiet` after `deploy:starting`. Solid Queue has no quiet mode: the `SIGTERM` it sends starts a shutdown, so jobs stopped for the whole deploy. The service is now stopped after `deploy:updated` and started after `deploy:published` ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). - Ruby 3.1 or later is required ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). - Capistrano 3.5 or later is required: `Capistrano::Plugin` doesn't exist before ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). +- The service starts Solid Queue with `bin/jobs`, as Solid Queue documents, instead of `rake solid_queue:start`. The application needs `bin/jobs`: Rails 8 applications have it, and `bin/rails solid_queue:install` creates it. Run `cap solid_queue:install` again to update an installed service ([#16](https://github.com/codeur/capistrano-solid_queue/pull/16)). ### Removed - `solid_queue:reload` and the `ExecReload=` line of the service: the `SIGTSTP` it sent didn't reload Solid Queue ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). +- `solid_queue:quiet`: Solid Queue has no quiet mode, the `SIGTERM` it sent started a shutdown. `solid_queue:stop` stops Solid Queue gracefully ([#16](https://github.com/codeur/capistrano-solid_queue/pull/16)). ### Fixed @@ -30,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - `solid_queue:uninstall` removes only the unit of the service, not every file whose name starts with it ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). - `solid_queue:status` shows the status of a stopped service instead of failing ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). - The README lists the hooks the plugin registers ([#14](https://github.com/codeur/capistrano-solid_queue/pull/14)), tells to enable lingering for user services, and links to the right code of conduct ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). +- The README says when the gem isn't needed (Solid Queue running inside Puma) and how to pass `bin/jobs` options ([#16](https://github.com/codeur/capistrano-solid_queue/pull/16)). - The gem's changelog link points to this file, and the gem no longer ships its outdated RBS signature, `.standard.yml` and `Rakefile` ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)). ## [0.1.3] - 2026-11-09 diff --git a/README.md b/README.md index 96596ff..f397dcb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Capistrano Systemd integration for SolidQueue +Runs [Solid Queue](https://github.com/rails/solid_queue) in its own process, with `bin/jobs`, as a systemd service. The application needs `bin/jobs`: Rails 8 applications have it, and `bin/rails solid_queue:install` creates it. If Solid Queue runs inside Puma with its plugin (`plugin :solid_queue`), you don't need this gem: both would start a Solid Queue supervisor. + Adds the following capistrano commands: ```sh @@ -7,7 +9,6 @@ cap solid_queue:disable # Disable solid_queue systemd service cap solid_queue:enable # Enable solid_queue systemd service cap solid_queue:generate # Generate solid_queue systemd service cap solid_queue:install # Install solid_queue systemd service -cap solid_queue:quiet # Quiet solid_queue (start graceful termination) cap solid_queue:restart # Restart solid_queue service via systemd cap solid_queue:start # Start solid_queue service via systemd cap solid_queue:status # Get solid_queue service status via systemd @@ -122,6 +123,12 @@ set :solid_queue_service_unit_env_files, ["/var/www/my_app/shared/.env", "-/etc/ When they aren't set, the `:service_unit_env_vars` and `:service_unit_env_files` variables, also read by capistrano3-puma and capistrano-sidekiq, are used. +Solid Queue reads the options of `bin/jobs` from environment variables too, for instance: + +```ruby +set :solid_queue_service_unit_env_vars, ["SOLID_QUEUE_CONFIG=config/calendar.yml", "SOLID_QUEUE_SKIP_RECURRING=true"] +``` + ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/lib/capistrano/tasks/solid_queue.rake b/lib/capistrano/tasks/solid_queue.rake index 9a7d656..bd4c7c9 100644 --- a/lib/capistrano/tasks/solid_queue.rake +++ b/lib/capistrano/tasks/solid_queue.rake @@ -46,13 +46,6 @@ namespace :solid_queue do # rubocop:disable Metrics end end - desc "Quiet solid_queue (start graceful termination)" - task :quiet do - on roles(fetch(:solid_queue_role)) do - plugin.execute_systemd("kill", "-s", "SIGTERM", fetch(:solid_queue_service_unit_name), raise_on_non_zero_exit: false) - end - end - desc "Start solid_queue service via systemd" task :start do on roles(fetch(:solid_queue_role)) do diff --git a/lib/capistrano/templates/solid_queue.service.erb b/lib/capistrano/templates/solid_queue.service.erb index a9353c8..fc64395 100644 --- a/lib/capistrano/templates/solid_queue.service.erb +++ b/lib/capistrano/templates/solid_queue.service.erb @@ -12,7 +12,7 @@ Environment='RAILS_ENV=<%= fetch(:rails_env, fetch(:stage)) %>' Environment='<%= variable.to_s.upcase %>=<%= capture(:printf, "%s", %("#{value.to_s.gsub('"', '\"')}")) %>' <% end -%> WorkingDirectory=<%= current_path %> -ExecStart=<%= capture(:echo, SSHKit.config.command_map[:bundle]).strip %> exec rake solid_queue:start +ExecStart=<%= capture(:echo, SSHKit.config.command_map[:bundle]).strip %> exec bin/jobs ExecStop=/bin/kill -TERM $MAINPID Environment=MALLOC_ARENA_MAX=2 <% fetch(:solid_queue_service_unit_env_vars).each do |variable| -%> diff --git a/test/capistrano/test_service_unit.rb b/test/capistrano/test_service_unit.rb index 432e187..e41963c 100644 --- a/test/capistrano/test_service_unit.rb +++ b/test/capistrano/test_service_unit.rb @@ -20,6 +20,10 @@ def test_user_service_has_no_user_line refute_match(/^User=/, generate_unit) end + def test_service_starts_solid_queue_with_bin_jobs + assert_match(/^ExecStart=\S+.* exec bin\/jobs$/, generate_unit) + end + def test_service_has_no_reload_command refute_includes generate_unit, "ExecReload" end diff --git a/test/capistrano/test_systemctl_failure.rb b/test/capistrano/test_systemctl_failure.rb index d4b2c99..32b4064 100644 --- a/test/capistrano/test_systemctl_failure.rb +++ b/test/capistrano/test_systemctl_failure.rb @@ -5,28 +5,21 @@ class Capistrano::TestSystemctlFailure < Minitest::Test include CapistranoProject - def test_quiet_goes_on_when_systemctl_fails - run_cap("solid_queue:quiet", stage_config: 'SSHKit.config.command_map[:"/bin/systemctl"] = "false"') do |output, status| - assert_includes output, "false --user kill -s SIGTERM app_solid_queue_preprod" + def test_status_goes_on_when_the_service_is_not_running + run_cap("solid_queue:status", stage_config: 'SSHKit.config.command_map[:"/bin/systemctl"] = "false"') do |output, status| + assert_includes output, "false --user status app_solid_queue_preprod" assert status.success?, output end end - def test_quiet_goes_on_when_systemctl_fails_as_system_user + def test_status_goes_on_when_the_service_is_not_running_as_system_user stage_config = <<~RUBY set :solid_queue_systemctl_user, :system SSHKit.config.command_map[:sudo] = "false" RUBY - run_cap("solid_queue:quiet", stage_config: stage_config) do |output, status| - assert_includes output, "false /bin/systemctl kill -s SIGTERM app_solid_queue_preprod" - assert status.success?, output - end - end - - def test_status_goes_on_when_the_service_is_not_running - run_cap("solid_queue:status", stage_config: 'SSHKit.config.command_map[:"/bin/systemctl"] = "false"') do |output, status| - assert_includes output, "false --user status app_solid_queue_preprod" + run_cap("solid_queue:status", stage_config: stage_config) do |output, status| + assert_includes output, "false /bin/systemctl status app_solid_queue_preprod" assert status.success?, output end end diff --git a/test/capistrano/test_tasks.rb b/test/capistrano/test_tasks.rb index 15fcdf2..0764d7d 100644 --- a/test/capistrano/test_tasks.rb +++ b/test/capistrano/test_tasks.rb @@ -72,11 +72,12 @@ def test_deploy_stops_then_starts_the_service end end - def test_there_is_no_reload_task + def test_there_is_no_reload_or_quiet_task run_cap("--tasks") do |output, status| assert status.success?, output assert_includes output, "solid_queue:restart" refute_includes output, "solid_queue:reload" + refute_includes output, "solid_queue:quiet" end end end