仅在特定服务器上调用delay_job capistrano任务 [英] Invoke delayed_job capistrano tasks only on specific servers

查看:63
本文介绍了仅在特定服务器上调用delay_job capistrano任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个专用服务器来处理delay_job任务。我只想在此服务器上启动,停止和重新启动delay_job worker。我使用的是delay_job提供的capistrano食谱。

I have a dedicated server for delayed_job tasks. I want to start, stop, and restart delayed_job workers on only this server. I am using the capistrano recipes provided by delayed_job.

当我只有1台服务器时,这是我的配置:

When I only had 1 server, this was my config:

before "deploy:restart", "delayed_job:stop"
after  "deploy:restart", "delayed_job:start"

after "deploy:stop",    "delayed_job:stop"
after "deploy:start",   "delayed_job:start"

现在,我只想将这些钩子应用于到单独的delay_job服务器( role:delayed_job< ip地址> )。这可以做得优雅吗?我是否必须将每个delay_job任务包装在meta任务中?还是自己写任务而不使用延迟工作提供的任务?

Now I want to have those hooks only apply to a separate delayed_job server (role :delayed_job <ip address>). Is this possible to do elegantly? Do I have to wrap each delayed_job tasks in a meta task? Or write my own tasks and not use the ones provided by delayed job?

推荐答案

在Capistrano中定义任务时,您可以限制将任务执行到特定角色。您可以通过:role 选项来实现此目的。

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.

似乎默认的delay_job Capistrano食谱就是这样做的。

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

根据源代码,任务从:delayed_job_server_role 配置变量中获取角色列表。

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

回到问题所在,要将任务的执行范围缩小到特定的服务器组,请在 deploy.rb

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

然后将:delayed_job_server_role 设置为该名称

set :delayed_job_server_role, :worker

仅此而已。现在将执行任务,但只执行:worker 角色中列出的服务器。

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

这篇关于仅在特定服务器上调用delay_job capistrano任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆