Minor database refactoring
This commit is contained in:
parent
635dfd948e
commit
707fb9f22d
4 changed files with 14 additions and 7 deletions
|
@ -7,12 +7,17 @@
|
||||||
(def test-db "grub-test")
|
(def test-db "grub-test")
|
||||||
|
|
||||||
(defn short-delay []
|
(defn short-delay []
|
||||||
(<!! (timeout 1)))
|
(<!! (timeout 20)))
|
||||||
|
|
||||||
|
(defn get-test-grub []
|
||||||
|
{:_id (str "grub" (rand-int 10000))
|
||||||
|
:grub (str "testtext" (rand-int 1000))
|
||||||
|
:completed ([true false] (rand-int 1))})
|
||||||
|
|
||||||
(describe
|
(describe
|
||||||
"grub.db"
|
"grub.db"
|
||||||
(before (do (db/connect-and-handle-events test-db)
|
(before-all (db/connect-and-handle-events test-db))
|
||||||
(mc/drop db/grub-collection)))
|
(before (mc/drop db/grub-collection))
|
||||||
(describe "Create grub"
|
(describe "Create grub"
|
||||||
(it "should create a grub when a create event comes"
|
(it "should create a grub when a create event comes"
|
||||||
(let [test-grub "testgrub"
|
(let [test-grub "testgrub"
|
||||||
|
|
|
@ -38,8 +38,7 @@
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
(let [port 3000]
|
(let [port 3000]
|
||||||
(println (str "Starting server on localhost:" port))
|
(println (str "Starting server on localhost:" port))
|
||||||
(db/connect-and-handle-events)
|
|
||||||
(defonce stop-server (httpkit/run-server app {:port port}))
|
(defonce stop-server (httpkit/run-server app {:port port}))
|
||||||
(when (some #(= % "integration") args)
|
(when (some #(= % "integration") args)
|
||||||
(integration-test/run)
|
(integration-test/run port)
|
||||||
(stop-server))))
|
(stop-server))))
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
(let [grub (-> event
|
(let [grub (-> event
|
||||||
(select-keys [:_id :grub])
|
(select-keys [:_id :grub])
|
||||||
(assoc :completed false))]
|
(assoc :completed false))]
|
||||||
(when (and (:_id grub) (:grub grub)) (mc/insert grub-collection grub))))
|
(mc/insert grub-collection grub)))
|
||||||
|
|
||||||
(defmethod handle-event :complete [event]
|
(defmethod handle-event :complete [event]
|
||||||
(mc/update grub-collection
|
(mc/update grub-collection
|
||||||
|
@ -57,3 +57,5 @@
|
||||||
(handle-incoming-events!)
|
(handle-incoming-events!)
|
||||||
(m/connect!)
|
(m/connect!)
|
||||||
(m/set-db! (m/get-db db-name))))
|
(m/set-db! (m/get-db db-name))))
|
||||||
|
|
||||||
|
(connect-and-handle-events default-db)
|
||||||
|
|
|
@ -37,7 +37,8 @@
|
||||||
(defn handle-incoming-events []
|
(defn handle-incoming-events []
|
||||||
(let [[incoming incoming'] (fan-out incoming-events 2)]
|
(let [[incoming incoming'] (fan-out incoming-events 2)]
|
||||||
(do-chan! push-event-to-others incoming)
|
(do-chan! push-event-to-others incoming)
|
||||||
(go-loop (let [event (<! incoming')]
|
(go-loop (let [event (<! incoming')
|
||||||
|
parsed-event (dissoc event :ws-channel)]
|
||||||
(>! @db/incoming-events event)))))
|
(>! @db/incoming-events event)))))
|
||||||
|
|
||||||
(defn websocket-handler [request]
|
(defn websocket-handler [request]
|
||||||
|
|
Loading…
Reference in a new issue