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`.
This commit is contained in:
Javi Martín
2023-06-29 15:39:25 +02:00
parent 59d260c891
commit ee9cd881e0
2 changed files with 2 additions and 1 deletions

View File

@@ -40,6 +40,7 @@ set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb"
set :delayed_job_workers, 2 set :delayed_job_workers, 2
set :delayed_job_roles, :background set :delayed_job_roles, :background
set :delayed_job_monitor, true
set :whenever_roles, -> { :app } set :whenever_roles, -> { :app }

View File

@@ -42,5 +42,5 @@ end
every :reboot do every :reboot do
command "cd #{@path} && bundle exec puma -C config/puma/#{@environment}.rb" 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 # 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 end