仅在特定服务器上调用delayed_job capistrano任务
我有一个专门的服务器用于delayed_job 任务。我想仅在该服务器上启动、停止和重新启动delayed_job工作线程。我正在使用delayed_job提供的capistrano食谱。
当我只有 1 台服务器时,这是我的配置:
before "deploy:restart", "delayed_job:stop"
after "deploy:restart", "delayed_job:start"
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
现在我想让这些钩子仅应用于单独的delayed_job服务器(角色:delayed_job
) 。这可以优雅地做到吗?我是否必须将每个delayed_job 任务包装在元任务中?或者自己写任务而不使用延迟工作提供的任务?
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.
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"
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在 Capistrano 中定义任务时,您可以将任务的执行限制为特定角色。执行此操作的方法是传递
:role
选项。看来默认delayed_job Capistrano配方就是这样做的。
根据源代码,任务从
:delayed_job_server_role
配置变量中获取角色列表。回到您的问题,要将任务的执行范围缩小到特定的服务器组,请在
deploy.rb
中定义一个新角色(例如工作人员),然后设置
:delayed_job_server_role
:delayed_job_server_role code> 到那个名字就这样了。现在,任务将被执行,但仅限于
:worker
角色中列出的服务器。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.
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
Then set the
:delayed_job_server_role
to that nameThat's all. Now the tasks will be executed, but only to the servers listed in the
:worker
role.