This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-02
Channels
- # adventofcode (5)
- # arachne (2)
- # bangalore-clj (1)
- # beginners (8)
- # boot (195)
- # cider (28)
- # cljs-dev (35)
- # cljsrn (4)
- # clojure (295)
- # clojure-brasil (5)
- # clojure-gamedev (2)
- # clojure-greece (2)
- # clojure-korea (13)
- # clojure-russia (60)
- # clojure-spec (58)
- # clojure-uk (92)
- # clojurescript (31)
- # clojurex (4)
- # css (1)
- # cursive (13)
- # datomic (40)
- # devcards (2)
- # emacs (17)
- # events (1)
- # flambo (3)
- # garden (9)
- # hoplon (31)
- # jobs (3)
- # klipse (1)
- # lein-figwheel (1)
- # london-clojurians (1)
- # luminus (2)
- # mount (36)
- # off-topic (13)
- # onyx (8)
- # pamela (1)
- # pedestal (1)
- # planck (3)
- # proto-repl (16)
- # protorepl (11)
- # re-frame (78)
- # reagent (4)
- # rethinkdb (6)
- # ring-swagger (1)
- # specter (8)
- # untangled (10)
- # vim (1)
hi there! how to start all states in current namespace only?
i have 10 or more states and want to avoid enumerate them all
(mount/start #'foo #'bar ....)
@mike1452: hey Mike, mount does not have API to scope the states by a namespace, but you can easily do it by:
dev=> (require '[clojure.string :as s])
dev=> (defn start-ns [ns]
(->> (mount/find-all-states)
(filter #(s/starts-with? % ns))
mount/start))
dev=> (start-ns "#'neo.conf")
INFO neo.conf - loading config from dev/resources/config.edn
{:started ["#'neo.conf/config"]}
I just opened a mount/find-all-states
function in 0.1.11-SNAPSHOT
. (it used to be private)
@tolitius Thanx! 🙂
@tolitius is it correct way to check?
dev=> ((mount/running-states) "#'app.db/conn")
nil
dev=> (mount/start)
{:started ["#'app.conf/config" "#'app.db/conn" "#'app.www/nyse-app" "#'app.example/nrepl"]}
dev=> ((mount/running-states) "#'app.db/conn")
"#'app.db/conn"
this is a bit cleaner@tolitius If i have states: config, conn and obj - all of them in current namespace. And I want to not start conn if config not started. And not start obj if conn is not started. Under "not started" i mean any case that is not success in terms of state. For example, if I've got Exception during conn - it is "not success" cause resource is unavailable. What value should I put to conn state if "not success"? (mount.core.NotStartedState. "conn") ? Have you some semantics for values? So and I want to check in depended states if state is not started then I log error. "bit cleaner" variant is not handy for such case.
or it is error state and I should introduce some values for "error state" and check for "not started" and "error state"?
it might have to do with: https://github.com/tolitius/mount/issues/50
let's say you have 3 states: config
, conn
and obj
the problem you're trying to solve is:
* not to start conn
on case you could not start conf
* not to start obj
on case you could not start conn
?
not start conn if conf not-started or in error state
in case we are talking about just (mount/start ...)
not start conn if conf in error state
is taken care of, since mount will stop in case there is an error starting conf
not start conn if conf not-started state
should also be handled in case conf
is injected in conn
"since mount will stop in case there is an error starting" - that is what I want, but didn't catch.
I put intentionally 1/0
and config and all depended states will be in started state but iti is not true
mount didn't catch that i've got and exeception
boot.user=> (defstate a :start (/ 1 0))
#'boot.user/a
boot.user=> (defstate b :start (println "starting a with b:" b))
#'boot.user/b
boot.user=> (mount/start)
java.lang.RuntimeException: could not start [#'boot.user/a] due to
java.lang.ArithmeticException: Divide by zero
boot.user=>
boot.user=> (mount/running-states)
#{}
hmmm, I will check right now ones more
boot.user=> (defstate ^:dynamic config :start (do (/ 1 0) (println "config is started")))
#'boot.user/config
boot.user=> (defstate db :start (println "starting db with config" config))
#'boot.user/db
boot.user=> (mount/start)
java.lang.RuntimeException: could not start [#'boot.user/config] due to
java.lang.ArithmeticException: Divide by zero
boot.user=> (mount/running-states)
#{}
no such var mount/running-states
is it in 0.1.11 ?
ok, cool. mount will not start if got an unhandled Exception
but, what if I have try-catch block inside and process Exception my self. What value should i return in order to tell mount this is not correct state?
I mean
in case you want to signal a problem don't do try/catch
, or if you need to do it re throw the exception
@tolitius got it! thanx!