生产佣金任务不承认我的模型

时间:2021-08-30 21:17:02

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:

当我运行Heroku Bamboo时,这从来都不是问题。现在,在Cedar上,每当我尝试从服务器上的rake任务中访问我的模型时,我都会收到错误。 rake db:seed,标准rake任务以及我自己的自定义构建任务明确包括:environment。我甚至多余地这样做:

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:

我在其他地方找不到任何关于这个问题的提及,所有这些任务都在开发中完美运行。感谢您的任何见解,这里是完整的错误消息,一旦他们在Heroku上遇到我的模型,rake任务就会吐出来:

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

2 个解决方案

#1


20  

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.

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

# 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!

希望这有帮助!

#2


1  

I had threadsafe! = true configured in my production environment at config/environments/production.rb

我有线程安全! =在我的生产环境中在config / environments / production.rb中配置为true

Disabling this solves the problem.

禁用此功能可以解决问题。

The answer found here: rake aborted! uninitialized constant Object::Country, why can't see model? gives some more explanation and other workaround options (particularly the last link)

答案在这里找到:耙子流产了!未初始化的常量Object :: Country,为什么看不到模型?提供更多解释和其他解决方案选项(特别是最后一个链接)

#1


20  

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.

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

# 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!

希望这有帮助!

#2


1  

I had threadsafe! = true configured in my production environment at config/environments/production.rb

我有线程安全! =在我的生产环境中在config / environments / production.rb中配置为true

Disabling this solves the problem.

禁用此功能可以解决问题。

The answer found here: rake aborted! uninitialized constant Object::Country, why can't see model? gives some more explanation and other workaround options (particularly the last link)

答案在这里找到:耙子流产了!未初始化的常量Object :: Country,为什么看不到模型?提供更多解释和其他解决方案选项(特别是最后一个链接)