Connect db to MONGOHQ_URL if it exists
This commit is contained in:
parent
f10f47274c
commit
b454e782bf
2 changed files with 19 additions and 12 deletions
|
@ -53,14 +53,14 @@
|
||||||
(integration-test/run integration-test-port)
|
(integration-test/run integration-test-port)
|
||||||
(stop-server)))
|
(stop-server)))
|
||||||
|
|
||||||
(defn start-production-server [port]
|
(defn start-production-server [{:keys [port mongo-url]}]
|
||||||
(reset! js-file "/js/grub.js")
|
(reset! js-file "/js/grub.js")
|
||||||
(let [db-chan (db/connect-production-database)]
|
(let [db-chan (db/connect-production-database mongo-url)]
|
||||||
(ws/pass-received-events-to-clients-and-db db-chan)
|
(ws/pass-received-events-to-clients-and-db db-chan)
|
||||||
(println (str "Starting production server on localhost:" port))
|
(println (str "Starting production server on localhost:" port))
|
||||||
(start-server port)))
|
(start-server port)))
|
||||||
|
|
||||||
(defn start-development-server [port]
|
(defn start-development-server [{:keys [port]}]
|
||||||
(let [db-chan (db/connect-development-database)]
|
(let [db-chan (db/connect-development-database)]
|
||||||
(ws/pass-received-events-to-clients-and-db db-chan)
|
(ws/pass-received-events-to-clients-and-db db-chan)
|
||||||
(println (str "Starting development server on localhost:" port))
|
(println (str "Starting development server on localhost:" port))
|
||||||
|
@ -84,6 +84,8 @@
|
||||||
:default default-port
|
:default default-port
|
||||||
:parse-fn #(Integer/parseInt %)
|
:parse-fn #(Integer/parseInt %)
|
||||||
:validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
|
:validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
|
||||||
|
["-m" "--mongo-url URL"
|
||||||
|
:default (System/getenv "MONGOHQ_URL")]
|
||||||
;; A boolean option defaulting to nil
|
;; A boolean option defaulting to nil
|
||||||
["-h" "--help"]])
|
["-h" "--help"]])
|
||||||
|
|
||||||
|
@ -98,15 +100,16 @@
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
(let [{:keys [options arguments errors summary]} (parse-opts args cli-options)]
|
(let [{:keys [options arguments errors summary]} (parse-opts args cli-options)]
|
||||||
;; Handle help and error conditions
|
;; Handle help and error conditions
|
||||||
|
(println "options:" options)
|
||||||
(cond
|
(cond
|
||||||
(:help options) (exit 0 (usage summary))
|
(:help options) (exit 0 (usage summary))
|
||||||
(not= (count arguments) 1) (exit 1 (usage summary))
|
(not= (count arguments) 1) (exit 1 (usage summary))
|
||||||
errors (exit 1 (error-msg errors)))
|
errors (exit 1 (error-msg errors)))
|
||||||
;; Execute program with options
|
;; Execute program with options
|
||||||
(case (first arguments)
|
(case (first arguments)
|
||||||
"development" (start-development-server (:port options))
|
"development" (start-development-server options)
|
||||||
"dev" (start-development-server (:port options))
|
"dev" (start-development-server options)
|
||||||
"production" (start-production-server (:port options))
|
"production" (start-production-server options)
|
||||||
"prod" (start-production-server (:port options))
|
"prod" (start-production-server options)
|
||||||
"integration" (run-integration-test)
|
"integration" (run-integration-test)
|
||||||
(exit 1 (usage summary)))))
|
(exit 1 (usage summary)))))
|
||||||
|
|
|
@ -83,15 +83,19 @@
|
||||||
(handle-event event)
|
(handle-event event)
|
||||||
(recur))))
|
(recur))))
|
||||||
|
|
||||||
(defn connect-and-handle-events [db-name]
|
(defn connect-and-handle-events [db-name & [mongo-url]]
|
||||||
(let [in (chan)]
|
(let [in (chan)]
|
||||||
(handle-incoming-events in)
|
(handle-incoming-events in)
|
||||||
(m/connect!)
|
(if mongo-url
|
||||||
(m/set-db! (m/get-db db-name))
|
(do (println "Connected to mongo via url:" mongo-url)
|
||||||
|
(m/connect-via-uri! mongo-url))
|
||||||
|
(do (println "Connected to mongo at localhost:" db-name)
|
||||||
|
(m/connect!)
|
||||||
|
(m/set-db! (m/get-db db-name))))
|
||||||
in))
|
in))
|
||||||
|
|
||||||
(defn connect-production-database []
|
(defn connect-production-database [mongo-url]
|
||||||
(connect-and-handle-events production-db))
|
(connect-and-handle-events production-db mongo-url))
|
||||||
|
|
||||||
(defn connect-development-database []
|
(defn connect-development-database []
|
||||||
(connect-and-handle-events development-db))
|
(connect-and-handle-events development-db))
|
||||||
|
|
Loading…
Add table
Reference in a new issue