2013-04-26 61 views
0

我試圖使用neo4j gem部署到Heroku的jruby rails應用程序。本地運行工作正常,但當我打#NEW(//新)在Heroku的結束,我得到:Neo4j在部署到Heroku後未自動啓動

NoMethodError (undefined method `reference_node' for nil:NilClass): 

之後[一些研究] [1],這似乎是我的Neo4j服務器甚至沒有運行。

所以我不得不這樣做

heroku run rails console 

然後

Neo4j.start 

..in爲了讓我的應用程序工作。但爲什麼Neo4j不知道只是醒來並開始?

這是我Gemfile.lock的:

GEM 
    remote: https://rubygems.org/ 
    specs: 
    actionmailer (3.2.13) 
     actionpack (= 3.2.13) 
     mail (~> 2.5.3) 
    actionpack (3.2.13) 
     activemodel (= 3.2.13) 
     activesupport (= 3.2.13) 
     builder (~> 3.0.0) 
     erubis (~> 2.7.0) 
     journey (~> 1.0.4) 
     rack (~> 1.4.5) 
     rack-cache (~> 1.2) 
     rack-test (~> 0.6.1) 
     sprockets (~> 2.2.1) 
    activemodel (3.2.13) 
     activesupport (= 3.2.13) 
     builder (~> 3.0.0) 
    activerecord (3.2.13) 
     activemodel (= 3.2.13) 
     activesupport (= 3.2.13) 
     arel (~> 3.0.2) 
     tzinfo (~> 0.3.29) 
    activeresource (3.2.13) 
     activemodel (= 3.2.13) 
     activesupport (= 3.2.13) 
    activesupport (3.2.13) 
     i18n (= 0.6.1) 
     multi_json (~> 1.0) 
    arel (3.0.2) 
    builder (3.0.4) 
    coffee-rails (3.2.2) 
     coffee-script (>= 2.2.0) 
     railties (~> 3.2.0) 
    coffee-script (2.2.0) 
     coffee-script-source 
     execjs 
    coffee-script-source (1.6.2) 
    diff-lcs (1.2.4) 
    erubis (2.7.0) 
    execjs (1.4.0) 
     multi_json (~> 1.0) 
    hike (1.2.2) 
    i18n (0.6.1) 
    journey (1.0.4) 
    jquery-rails (2.2.1) 
     railties (>= 3.0, < 5.0) 
     thor (>= 0.14, < 2.0) 
    json (1.7.7-java) 
    mail (2.5.3) 
     i18n (>= 0.4.0) 
     mime-types (~> 1.16) 
     treetop (~> 1.4.8) 
    mime-types (1.23) 
    multi_json (1.7.2) 
    neo4j (2.2.3-java) 
     activemodel (>= 3.0.0, < 3.3) 
     neo4j-wrapper (= 2.2.3) 
     orm_adapter (>= 0.0.3) 
     railties (>= 3.0.0, < 3.3) 
    neo4j-community (1.8.1-java) 
    neo4j-core (2.2.3-java) 
     neo4j-community (>= 1.8.1, < 1.9) 
     neo4j-cypher (~> 1.0.0) 
    neo4j-cypher (1.0.0) 
    neo4j-wrapper (2.2.3-java) 
     neo4j-core (= 2.2.3) 
    orm_adapter (0.4.0) 
    polyglot (0.3.3) 
    puma (1.6.3-java) 
     rack (~> 1.2) 
    rack (1.4.5) 
    rack-cache (1.2) 
     rack (>= 0.4) 
    rack-ssl (1.3.3) 
     rack 
    rack-test (0.6.2) 
     rack (>= 1.0) 
    rails (3.2.13) 
     actionmailer (= 3.2.13) 
     actionpack (= 3.2.13) 
     activerecord (= 3.2.13) 
     activeresource (= 3.2.13) 
     activesupport (= 3.2.13) 
     bundler (~> 1.0) 
     railties (= 3.2.13) 
    railties (3.2.13) 
     actionpack (= 3.2.13) 
     activesupport (= 3.2.13) 
     rack-ssl (~> 1.3.2) 
     rake (>= 0.8.7) 
     rdoc (~> 3.4) 
     thor (>= 0.14.6, < 2.0) 
    rake (10.0.4) 
    rdoc (3.12.2) 
     json (~> 1.4) 
    rspec-core (2.13.1) 
    rspec-expectations (2.13.0) 
     diff-lcs (>= 1.1.3, < 2.0) 
    rspec-mocks (2.13.1) 
    rspec-rails (2.13.0) 
     actionpack (>= 3.0) 
     activesupport (>= 3.0) 
     railties (>= 3.0) 
     rspec-core (~> 2.13.0) 
     rspec-expectations (~> 2.13.0) 
     rspec-mocks (~> 2.13.0) 
    sass (3.2.8) 
    sass-rails (3.2.6) 
     railties (~> 3.2.0) 
     sass (>= 3.1.10) 
     tilt (~> 1.3) 
    sprockets (2.2.2) 
     hike (~> 1.2) 
     multi_json (~> 1.0) 
     rack (~> 1.0) 
     tilt (~> 1.1, != 1.3.0) 
    therubyrhino (2.0.2) 
     therubyrhino_jar (>= 1.7.3) 
    therubyrhino_jar (1.7.4) 
    thor (0.18.1) 
    tilt (1.3.7) 
    treetop (1.4.12) 
     polyglot 
     polyglot (>= 0.3.1) 
    tzinfo (0.3.37) 
    uglifier (2.0.1) 
     execjs (>= 0.3.0) 
     multi_json (~> 1.0, >= 1.0.2) 

PLATFORMS 
    java 

DEPENDENCIES 
    coffee-rails (~> 3.2.1) 
    jquery-rails 
    neo4j (>= 2.2.3) 
    puma 
    rails (= 3.2.13) 
    rspec-rails 
    sass-rails (~> 3.2.3) 
    therubyrhino 
    uglifier (>= 1.0.3) 

回答

3

這很可能是因爲Neo4j的啓動是不是(還)是線程安全的。 Neo4j實際上會在你第一次打你的應用時啓動。但是,根據請求的類型,您可能會遇到上述錯誤。具體來說,Neo4j啓動時對應用程序的多個請求將導致錯誤,直到應用程序重新啓動。

我爲此提交了一個修復程序(請參閱hereherehere),並且它已合併。但是,它尚未被納入官方寶石發佈。

如果要解決這個問題,現在,你有兩個選擇:

- 點到neo4核心主分支

- 自動啓動,使用下面的猴子補丁啓動Neo4j的。這圍繞着線程安全問題,因爲在Neo4j完成啓動之前,Rails不會接受任何請求。

#config/initializers/neo4j.rb 
require 'neo4j' 
module Neo4j 
    class Railtie < ::Rails::Railtie 
    initializer "neo4j.db.start", :after => "neo4j.start" do |app| 
     Neo4j.start if app.config.neo4j.auto_start 
    end 
    end 
end 

#config/application.rb 
config.neo4j.auto_start = true 

請注意,即使有這些修復,我仍然有麻煩的彪馬web服務器拋出奇怪的例外。我建議torquebox-lite用於生產使用 - 它從來沒有爲我倒下。

UPDATE:Neo4j.rb v2.2.4(2013年5月19日發佈)包含此修復程序,因此升級後不再需要此修補程序。