Rails 2.3.5 线程安全!打破了我的迁移
我正在使用 jruby-1.5.3 和 Rails 2.3.5 应用程序。我刚刚开始使用以下方法来解决线程安全问题:
config.threadsafe!
config.eager_load_paths << "#{RAILS_ROOT}/lib"
效果很好,但是我注意到在部署到我的临时环境(与生产环境具有相同的配置)时,我得到了未定义的常量。例如,向角色表添加另一个角色的迁移:
class AddSuperAdminRole < ActiveRecord::Migration
def self.up
Role.create :rolename => 'super_admin'
end
end
抛出:
uninitialized constant AddSuperAdminRole::Role
它在开发环境中工作正常,因为我没有运行多线程,所以我知道这就是问题所在。我也尝试过急于加载应用程序/模型路径,但这不起作用。如何让迁移在线程安全的情况下运行?
I'm using jruby-1.5.3 with a rails 2.3.5 app. I've just started playing around with thread safety using:
config.threadsafe!
config.eager_load_paths << "#{RAILS_ROOT}/lib"
Which works fine, I just noticed however on deployment to my staging environment (which has the same config as production) that I get undefined constants. For instance, a migration that adds another role to a Role table:
class AddSuperAdminRole < ActiveRecord::Migration
def self.up
Role.create :rolename => 'super_admin'
end
end
throws a:
uninitialized constant AddSuperAdminRole::Role
It works fine in dev environment because i'm not running that multithreaded so I know that's the issue. I've tried eager loading the app/models path also but that didn't work. How do I get migrations running with threadsafety?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
升级到 2.3.10 修复了这个问题。
upgrading to 2.3.10 fixed this.
来自票证 #2506。下面我链接了 Rails 中的线程安全方法。您将看到 config.dependency_loading 被设置为 false,因为它不是线程安全的,因此迁移会自动加载其依赖项。
以下是 Joshua Peek 在票证评论中对该问题的回应:
From ticket #2506 on the Rails Lighthouse site. Below i linked the threadsafe method in Rails. You'll see that
config.dependency_loading
is set to false because it's not thread safe and therefore the migrations are getting their dependencies auto-loaded.Here's Joshua Peek's response to the problem in comments to the ticket: