Rails,Mongoid&独角兽配置为Heroku [英] Rails, Mongoid & Unicorn config for Heroku

查看:137
本文介绍了Rails,Mongoid&独角兽配置为Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Mongoid 3,Rails 3.2.9和Unicorn进行生产。想要设置before_fork&用于连接到mongodb的after_fork,找到了以下活动记录的代码:

  before_fork do | server,worker | 
#用MongoDB或任何
替换(ActiveRecord :: Base)
ActiveRecord :: Base.connection.disconnect!
Rails.logger.info('与ActiveRecord断开连接)
结束
结束

after_fork do | server,worker |
#用MongoDB或任何
替换(如果已定义)?(ActiveRecord :: Base)
ActiveRecord :: Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
end

Mongoid的相关代码(连接和断开连接)?

更新:

您并不需要这么做,所以对于来看这个问题的人来说:



http: //mongoid.org/en/mongoid/docs/rails.html



<独角兽和乘客


当使用Unicorn或Passenger时,每次使用应用程序预加载或智能产卵时,子进程都会分叉,Mongoid将自动重新连接到master数据库,如果您在应用程序中手动执行此操作,则可能会删除您的代码。 / p>

尽管知道什么是等效的Mongoid代码仍然很有趣。

解决方案

您实际上不需要这样做,所以对于查看此问题的人来说,请参阅:

http://mongoid.org/en/mongoid/docs/rails.html



独角兽和乘客

使用独角兽或乘客时,当使用应用程序预加载或智能产卵时,Mongoid会自动重新连接到主数据库。如果你在应用程序中手动执行此操作,你可能会删除你的代码。



尽管知道什么是等效的Mongoid代码仍然很有趣。 >

I am using Mongoid 3, with Rails 3.2.9 and Unicorn for production. Would like to setup a before_fork & after_fork for the connection to mongodb, found the following code for active record:

before_fork do |server, worker|
  # Replace with MongoDB or whatever
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    Rails.logger.info('Disconnected from ActiveRecord')
  end
end

after_fork do |server, worker|
  # Replace with MongoDB or whatever
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Rails.logger.info('Connected to ActiveRecord')
  end
end

What is the relevant code for Mongoid (to connect and disconnect)?

Update:

You dont actually need to do this, so for people coming to view this question see:

http://mongoid.org/en/mongoid/docs/rails.html

"Unicorn and Passenger

When using Unicorn or Passenger, each time a child process is forked when using app preloading or smart spawning, Mongoid will automatically reconnect to the master database. If you are doing this in your application manually you may remove your code."

Though it would still be interesting to know what would be the equivalent Mongoid code.

解决方案

You dont actually need to do this, so for people coming to view this question see:

http://mongoid.org/en/mongoid/docs/rails.html

"Unicorn and Passenger

When using Unicorn or Passenger, each time a child process is forked when using app preloading or smart spawning, Mongoid will automatically reconnect to the master database. If you are doing this in your application manually you may remove your code."

Though it would still be interesting to know what would be the equivalent Mongoid code.

这篇关于Rails,Mongoid&amp;独角兽配置为Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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