生产Rake任务不识别我的模型 [英] Production Rake Tasks Don't Recognize My Models

查看:106
本文介绍了生产Rake任务不识别我的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行Heroku Bamboo时,这绝不是问题。现在,在Cedar上,每当我尝试从服务器上的rake任务中访问我的模型时,都会收到错误。这发生在 rake db:seed ,一个标准的rake任务,以及我自己定制的任务中,这些任务明确包含:environment。我甚至会这样做:

pre $ 命名空间:db do
desc更新数据库
任务:new_seed => :environment do
require'./Scraped_Data/Games/code/column-headers.rb'
require'csv'
require'net / http'
require'./config /environment.rb'

#此处的代码...

结束
结束

在其他地方我找不到这个问题,所有这些任务都在开发中完美运行。感谢您的任何见解,以下是在Heroku上遇到我的模型后即刻吐出的完整错误消息:

  rake中止了! 
未初始化的常量Object :: Movie
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in`const_missing '
/app/lib/tasks/new_seed.rake:187:in`block in load_scraped_data'
/app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0 .0 / lib / rest-open-uri.rb:37:在`open'
/app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/ rest-open-uri.rb:37:在`open'
/app/lib/tasks/new_seed.rake:148:in`load_scraped_data'
/app/lib/tasks/new_seed.rake: 550:在< top(required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task'块中(2级)。 rb:205:在`call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in`block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in`each'
/ app / vendor / bundle / ruby /1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in`execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9。 2.2 / lib / rake / task.rb:158:在`block中in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in`mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake -0.9.2.2 / lib / rake / task.rb:151:在`invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task。 rb:144:在`invoke'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in`invoke_task'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in'block(2 levels)in top_level'
/ app / vendor /bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in`each'
/app/vendor/bundle/ruby/1.9.1/gems/ rake-0.9.2.2 / lib / rake / application.rb:94:在`block in top_level'中
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake /application.rb:133:in` standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in`top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in`standard_exception_handling'
/ app /vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in`run'
/app/vendor/bundle/ruby/1.9.1/ gems / rake-0.9.2.2 / bin / rake:33:在< top(required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in`加载'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in`< main>'
任务:TOP => db:new_seed


解决方案

默认情况下,线程安全集合dependency_loading = false <
如果您想在应用程序中启用线程安全并在任务中访问模型,则需要加载它。


 #启用线程模式
config.threadsafe!
config.dependency_loading = true如果$ rails_rake_task



参考。: http://nowhereman.github.com/how-to/rails_thread_safe/



希望这有帮助!


When I was running Heroku Bamboo, this was never a problem. Now, on Cedar, I get errors whenever I try to access my models from within a rake task on the server. This happens with rake db:seed, a standard rake task, as well as my own custom built tasks that explicitly include :environment. I even do so redundantly:

namespace :db do
  desc "Update db"
  task :new_seed => :environment do
    require './Scraped_Data/Games/code/column-headers.rb'
    require 'csv'
    require 'net/http'
    require './config/environment.rb'

    # code here...

  end
end

I can't find any mention of this issue elsewhere, and all of these tasks run perfectly in development. Thanks for any insights, and here is the full error message rake tasks spit out as soon as they encounter a model of mine on Heroku:

rake aborted!
uninitialized constant Object::Movie
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing'
/app/lib/tasks/new_seed.rake:187:in `block in load_scraped_data'
/app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open'
/app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open'
/app/lib/tasks/new_seed.rake:148:in `load_scraped_data'
/app/lib/tasks/new_seed.rake:550:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => db:new_seed

解决方案

By default threadsafe set dependency_loading = false
If you want to enable threadsafe in your application and access to your models in your task, you'll need to load it.

# Enable threaded mode
config.threadsafe!
config.dependency_loading = true if $rails_rake_task


Ref.: http://nowhereman.github.com/how-to/rails_thread_safe/

Hope this help!

这篇关于生产Rake任务不识别我的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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