From ee9cd881e046a21ceafd12a0f6710c17282c50d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 29 Jun 2023 15:39:25 +0200 Subject: [PATCH] Restart DelayedJob workers after they crash DelayedJob offers the `--monitor` (aliased as `-m`) option to create a process that monitors the workers and restarts them when they crash. This change implies that, in order to stop the delayed job workers, we now need to pass the `-n` option when running `bin/delayed_job stop`: `RAILS_ENV=production bin/delayed_job -n 2 stop`. --- config/deploy.rb | 1 + config/schedule.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 145380bc3..acfacd108 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -40,6 +40,7 @@ set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb" set :delayed_job_workers, 2 set :delayed_job_roles, :background +set :delayed_job_monitor, true set :whenever_roles, -> { :app } diff --git a/config/schedule.rb b/config/schedule.rb index b9e3be61c..c8d1f1cb9 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -42,5 +42,5 @@ end every :reboot do command "cd #{@path} && bundle exec puma -C config/puma/#{@environment}.rb" # Number of workers must be kept in sync with capistrano's delayed_job_workers - command "cd #{@path} && RAILS_ENV=#{@environment} bin/delayed_job -n 2 restart" + command "cd #{@path} && RAILS_ENV=#{@environment} bin/delayed_job -m -n 2 restart" end