2012-03-22 3 views
7

Heroku Bamboo를 실행할 때 이것은 결코 문제가되지 않았습니다. 이제 Cedar에서 서버의 레이크 작업에서 내 모델에 액세스하려고 할 때마다 오류가 발생합니다. 이것은 표준 레이크 작업 인 rake db:seed뿐만 아니라 환경을 명시 적으로 포함하는 내 자신의 사용자 정의 빌드 작업에서도 발생합니다. 내가 다른 곳에서이 문제에 대한 언급을 찾을 수 없습니다제작 레이크 작업에서 내 모델을 인식하지 못합니다.

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 

,이 모든 작업은 개발에 완벽하게 실행 : 난 그렇게 중복 않습니다. 내가 threadsafe! = trueconfig/environments/production.rb

해제에 내 프로덕션 환경에서 구성한

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 
+1

나는 이것이 다른 이유로 실패한 것 같습니다. 특히 "heroku run console"을 실행하면 "Movie"를로드 할 수 있습니까? –

+0

예, 할 수 있습니다. 콘솔에서 모든 모델에 액세스하는 데 문제가 없습니다. 나는 영화 'heroku run console'을 통해 영화가 잘 작동하는지 다시 확인했다. –

+2

나는'threadsafe! = true'는 내 프로덕션 환경에서 구성되었습니다. 이로 인해 문제가 발생했습니다. –

답변

20

을 제공 설정 스레드 dependency_loading = 거짓
당신은 당신의 응용 프로그램에서 스레드 및 액세스 할 수 있도록하려는 경우 모델을로드하려면로드해야합니다.

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


참고 : http://nowhereman.github.com/how-to/rails_thread_safe/

희망이 도움이!

+0

'$ rails_rake_task'는 최신 버전의 rake 나 rails에서는 더 이상 정의되어 있지 않지만, 여전히 수동으로'$ rails_rake_task = true'를 Rakefile에 설정할 수 있습니다. –

1

: 여기에 어떤 통찰력을 주셔서 감사합니다, 그리고 그들에게 Heroku에 내 모델을 발생으로 전체 오류 메시지 레이크 작업을 빨리 뱉어입니다 이것은 문제를 해결합니다.

여기 대답은

: rake aborted! uninitialized constant Object::Country, why can't see model? 기본적으로 좀 더 설명과 다른 해결 옵션 (특히 마지막 링크)

관련 문제