Invoke delayed_job capistrano tasks only on specific servers

旧城冷巷雨未停 提交于 2019-12-03 03:10:45

When you define a task in Capistrano you can restrict the execution of the task to specific role(s). The way you do this is by passing the :role option.

It seems the default delayed_job Capistrano recipe does this.

desc "Stop the delayed_job process"
task :stop, :roles => lambda { roles } do
  run "cd #{current_path};#{rails_env} script/delayed_job stop"
end

According to the source code, the task fetches the list of roles from the :delayed_job_server_role configuration variable.

Back to your problem, to narrow the execution of the tasks to a specific group of servers, define a new role (for example worker) in your deploy.rb

role :worker, "192.168.1.1" # Assign the IP of your machine

Then set the :delayed_job_server_role to that name

set :delayed_job_server_role, :worker

That's all. Now the tasks will be executed, but only to the servers listed in the :worker role.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!