From 704cafc38514ba6460d6dc3305c9b2c4112f9c67 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Fri, 13 Nov 2020 16:06:51 +0100 Subject: [PATCH] restart delayed_job only for workers --- config/deploy.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 450c68861..a477644e5 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -3,6 +3,7 @@ require 'mina/git' require 'mina/rails' require 'mina/rbenv' +SHARED_WORKER_FILE_NAME = 'i_am_a_worker' # Basic settings: # domain - The hostname to SSH to. # deploy_to - Path to deploy into. @@ -12,7 +13,8 @@ require 'mina/rbenv' # Advanced settings: # forward_agent - SSH forward_agent # user - Username in the server to SSH to -# shared_dirs - Manually create these paths in shared/ on your server. +# shared_dirs, shared_files: +# - Manually create these paths in shared/ on your server. # They will be linked in the 'deploy:link_shared_paths' step. deploy_to = '/var/www/ds' @@ -23,6 +25,9 @@ shared_dirs = [ 'tmp/pids', 'vendor/bundle' ] +shared_files = [ + SHARED_WORKER_FILE_NAME +] set :domain, ENV.fetch('domain') set :deploy_to, deploy_to @@ -33,10 +38,17 @@ set :branch, ENV.fetch('branch') set :forward_agent, true set :user, 'ds' set :shared_dirs, shared_dirs +set :shared_files, shared_files set :rbenv_path, "/home/ds/.rbenv/bin/rbenv" puts "Deploy to #{ENV.fetch('domain')}, branch: #{ENV.fetch('branch')}" +def is_worker_machine? + # The presence of a file identify if a machine is a worker or not. + # This is useful in order to know whether or not to restart delayed_job + File.file?(Rails.root.join(SHARED_WORKER_FILE_NAME)) +end + # This task is the environment that is loaded for most commands, such as # `mina deploy` or `mina rake`. task :setup do @@ -95,10 +107,12 @@ namespace :service do desc "Restart delayed_job" task :restart_delayed_job do - command %{ - echo "-----> Restarting delayed_job service" - #{echo_cmd %[sudo systemctl restart delayed_job]} - } + if is_worker_machine? + command %{ + echo "-----> Restarting delayed_job service" + #{echo_cmd %[sudo systemctl restart delayed_job]} + } + end end end