ruby-on-rails - 如何在不关闭应用程序的情况下推送到 Heroku

标签 ruby-on-rails ruby-on-rails-3 heroku

只是想知道每个人如何将更新推送到 Heroku 上的生产服务器,而不会使应用程序关闭几秒钟?

推送到 Heroku(特别是使用像 Unicorn 这样的东西),需要一段时间才能加载网络应用程序。特别是当最终用户尝试访问该站点时。它们最终有 503 个页面。Unicorn 进程加载需要长达 30 秒到一分钟的时间。

最佳答案

要完成此任务,您需要做两件事,而且这并不简单。

1) 迁移需要向后兼容(即在应用程序运行时运行)。请参阅这篇文章:http://pedro.herokuapp.com/past/2011/7/13/rails_migrations_with_no_downtime/

2) 使用两个 heroku 应用程序进行部署。我就这个主题向 Heroku 开了一张票,这是他们的回复:

We're currently working on a solution to provide a zero-downtime deploy but do not have an ETA on when this might be available.

In the meantime a workaround that might be possible would be to deploy to two separate apps. You can push new code to the second app, spin it up, then move the domain names over to the second app. Wash and repeat on the next deploy. This is less than ideal but might get you the desired result in the interim.

如果你这样做,你会希望尽可能地实现自动化,因为有很多方法可以把它搞砸。这是关于该主题的文章:http://casperfabricius.com/site/2009/09/20/manage-and-rollback-heroku-deployments-capistrano-style/

为什么?

两个解决方案必须两者都完成,因为数据库迁移必须在代码的两个(实时和 future )版本中工作。一旦你做到了这一点,那么你就可以解决第二个问题,即让应用程序本身看起来不会出现故障。一旦推送开始,就没有支持的方式来旋转单个测功机。

更新: Heroku 现在有一个测试版功能。要使用,请在推送之前执行以下操作:

heroku labs:enable -a APP_NAME 预启动

这将改变应用程序在推送期间的行为。它将启动一个并行实例,该实例将预热两分钟。推送后几乎正好两分钟,所有流量都将路由到新应用程序。正如我上面提到的,要小心迁移,因为它们仍然是一个问题。

关于ruby-on-rails - 如何在不关闭应用程序的情况下推送到 Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10238409/

相关文章:

ruby-on-rails - rails : rspec fails after switching to postgreSQL

ruby-on-rails-3 - Rails 3.1 - 更改默认脚手架 View 和模板

python - Django 测试错误 "Permission denied to create database"- 使用 Heroku Postgres

ruby-on-rails - Rails STI Controller

ruby-on-rails - 如何为两个设计模型设置单点登录表单

ruby-on-rails - 循环非事件记录模型对象的属性

ruby-on-rails - Heroku/Unicorn 上的重复出现 rails 错误 - 'execution expired',一个 ActionView::Template::Error

heroku - 在 Heroku 上设置自定义域

javascript - 将 vendor js 文件(来自包装 Bootstrap )合并到 Rails 4 中

ruby-on-rails - 在 Rails 中存储全局共享数据结构的位置