仅在特定服务器上调用delayed_job capistrano任务

发布于 2024-12-01 15:46:38 字数 512 浏览 1 评论 0原文

我有一个专门的服务器用于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别挽留 2024-12-08 15:46:38

当您在 Capistrano 中定义任务时,您可以将任务的执行限制为特定角色。执行此操作的方法是传递 :role 选项。

看来默认delayed_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 配置变量中获取角色列表。

回到您的问题,要将任务的执行范围缩小到特定的服务器组,请在 deploy.rb 中定义一个新角色(例如工作人员)

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

,然后设置 :delayed_job_server_role:delayed_job_server_role code> 到那个名字

set :delayed_job_server_role, :worker

就这样了。现在,任务将被执行,但仅限于 :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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文