我正在使用Mongoid 3、Rails 3.2.9和Unicorn进行生产.想在fork&;在连接到mongodb后,找到以下活动记录代码:
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
Mongoid(连接和断开连接)的相关代码是什么?
Update:
你实际上不需要这样做,所以对于前来查看此问题的人,请参见:
http://mongoid.org/en/mongoid/docs/rails.html
"独角兽和乘客
当使用Unicorn或Passenger时,每次在使用应用程序预加载或智能生成时分支子进程时,Mongoid都会自动重新连接到主数据库.如果在应用程序中手动执行此操作,则可以删除代码."
尽管知道什么是等效的Mongoid代码仍然很有趣.