restart delayed_job only for workers

This commit is contained in:
clemkeirua 2020-11-13 16:06:51 +01:00 committed by simon lehericey
parent a9cee3a67e
commit 704cafc385

View file

@ -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