简体   繁体   English

仅在一个生产实例上运行发条(rails capistrano)

[英]Run clockwork only on one production instance (rails capistrano)

I have a production server with two instances app1 and app2 to which I use capistrano to deploy my application, ie: cap app1 deploy, cap app2 deploy. 我有一个具有两个实例app1和app2的生产服务器,我使用capistrano来向其部署我的应用程序,即:cap app1 deploy,cap app2 deploy。

I am now configuring the clockwork to schedule my delayed jobs. 我现在正在配置发条以安排延迟的工作。 But what happens the jobs are scheduled twice, because the clockwork process runs on both app1 and app2 after application is deployed. 但是将作业安排两次,因为部署应用程序后,发条流程同时在app1和app2上运行。

How can I force the capistrano to run the clockwork process only on app2 ? 如何强制capistrano仅在app2上运行发条过程?

Thanks for a hint. 感谢您的提示。 Miroslav 米罗斯拉夫

SOLUTION

Add the following settings into the deploy.rb: 将以下设置添加到deploy.rb中:

set :clockwork_role, :clock

And then configure only one of the instances to use the role :clock, ie: 然后仅配置一个实例使用角色:clock,即:

server 'URL', user: 'deploy', roles: %w{app db web clock}

In your case you can set some config variable to true in one case, and to false in the second, and check it when setting clockwork. 在您的情况下,您可以将某些配置变量设置为true ,然后将其设置为false ,并在设置发条时进行检查。

But want to mention that you are using different 'stages' (which are usually 'staging', 'production', 'qa', 'features', etc) for the different servers of one stage. 但是要提及的是,您为一个阶段的不同服务器使用了不同的“阶段”(通常是“阶段”,“生产”,“质量保证”,“功能”等)。 Capistrano has 'roles' (app, db, background jobs, etc) each can have several servers. Capistrano具有“角色”(应用,数据库,后台作业等),每个角色可以具有多个服务器。

Also please mention which capistrano version you're using - there were big changes from 2 to 3 还请说明您使用的是哪个版本的capistrano-从2到3的变化很大

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在生产中运行发条脚本 - How to run clockwork script in production 如何在安装了Capistrano 3和rvm的生产环境中运行Rails命令 - How to run rails commands in production with capistrano 3 and rvm installed 安排发条仅在一年中的特定日期运行 - Schedule clockwork to run only on a specific date of the year SSH + Rails:在一行中通过ssh会话运行Rails(和Capistrano)命令 - SSH + Rails: Run Rails (and Capistrano) commands with ssh session in one line 如何使用 Rails clockwork gem 运行 rake 任务? - How do I use Rails clockwork gem to run rake tasks? 使用Capistrano部署后,无法在运行Puma 3.6的AWS EC2实例的生产环境中访问Rails 5 App - Can't access the Rails 5 App in production on AWS EC2 instance running Puma 3.6 after deployment with Capistrano 在实例启动时运行Capistrano命令 - Run Capistrano Command on Instance Startup Rails中只有一个Model的实例 - Only one instance of a Model in Rails 不知道如何在使用 Rails 为 capistrano 3.8.0 运行“cap production deploy”时构建任务“start” - Don't know how to build task 'start' when run 'cap production deploy' for capistrano 3.8.0 with Rails 使用Capistrano和Rails无法生成图像和字体 - No images and fonts production using Capistrano and Rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM