我正在尝试在我的heroku dyno上启动我的clojure应用程序但是我在stuartsierra.component / start中继续得到错误。
(defrecord Listener [listener]
component/Lifecycle
(start [component]
(assoc component :listener (yada/listener
["/"
[(view/view-route)
routes/route-handler
["public/" (new-directory-resource (io/file "target/cljsbuild/public") {})]
[true (as-resource nil)]]]
(or (env :port) (get (read-config "resources/config.edn" {:profile :dev}) :webserver))
)))
(stop [component]
(when-let [close (-> component :listener :close)]
(close))
(assoc component :listener nil)))
(defn new-system []
(component/system-map
:listener (map->Listener {})
))
(def system nil)
(defn init []
(alter-var-root #'system
(constantly (new-system))))
(defn start []
(alter-var-root #'system component/start))
(defn stop []
(alter-var-root #'system
(fn [s] (when s (component/stop s)))))
(defn go []
(init)
(start))
(defn reset []
(stop)
(refresh :after 'web.core/go))
(defn -main
[& [port]]
(component/start (new-system))
(println "System Started")
@(promise))
这是我的所有stuartsierra.component代码的核心文件。当我在我的笔记本电脑上本地运行它lein repl
然后(go)
以及我只做lein run
时,这一切都非常有效。所以当我把它推到heroku dyno时,我很困惑为什么它不起作用。
我得到的错误是
Exception in thread "main" clojure.lang.ExceptionInfo: Error in component :listener in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :listener, :component #web.core.Listener{:listener nil}, :system #<SystemMap>}, compiling:(/tmp/form-init9049917434081554913.clj:1:73)
这告诉我:listener
中的nil
system-map
为lein repl
。当我在(go)
中进行本地检查((keys system)
(:listener)
}是(-> system :listener)
这是好的,这意味着监听器正在启动并且在系统中。
当我#web.core.Listener{:listener {:port 3300, :close #object[yada.aleph$listener$fn__21671 0xa5d4865 "yada.aleph$listener$fn__21671@a5d4865"], :server #object[aleph.netty$start_server$reify__13574 0x3cc9a232 "aleph.netty$start_server$reify__13574@3cc9a232"]}}
时,我得到:listener
这是完美的,因为端口已加载(3300)并且服务器已启动。
这使得我的heroku应用中nil
为public class ScoreCard { strong text
private double[] scores;
/**
* @param val
* @param low
* @param high
* @return low if val < low,
* high if val > high,
* val if val is between low and high
*/
private double constrain(double val, int low, int high) {
if (val < low)
return low;
if (val > high)
return high;
else
return val;
}
/**
* DEEP copy m into scores with each item contrained between 0 and 100.
* use method {@link this#constrain(double, int, int)}.
* For example, if s = {-15.2, 67.4, 126.8}, scores should become
* {0, 67.4, 100}, AND scores should be a DEEP copy of s.
* @param s (assume s is not null)
*/
public void setMarks(double[] s) {
for(int i = 0; i < s.length; i++) {
if (s[i] < 0 || s[i] > 100)
constrain(s[i], 0, 100);
this.scores[i] = s[i];
}
}
的原因更令人困惑
非常感谢任何帮助。感谢