This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-19
Channels
- # announcements (10)
- # aws (3)
- # aws-lambda (1)
- # babashka (24)
- # beginners (57)
- # boot (5)
- # calva (20)
- # chlorine-clover (3)
- # cider (14)
- # clj-kondo (37)
- # clojars (17)
- # clojure (200)
- # clojure-dev (40)
- # clojure-europe (9)
- # clojure-france (7)
- # clojure-gamedev (5)
- # clojure-hungary (4)
- # clojure-italy (8)
- # clojure-losangeles (2)
- # clojure-nl (9)
- # clojure-uk (97)
- # clojurebridge (1)
- # clojured (3)
- # clojuredesign-podcast (23)
- # clojurescript (13)
- # code-reviews (2)
- # component (22)
- # core-typed (7)
- # cursive (64)
- # datascript (12)
- # datomic (60)
- # emacs (6)
- # fulcro (54)
- # graalvm (11)
- # graphql (3)
- # hoplon (25)
- # jobs (1)
- # joker (85)
- # juxt (5)
- # kaocha (10)
- # klipse (8)
- # malli (2)
- # off-topic (36)
- # parinfer (1)
- # pathom (1)
- # re-frame (9)
- # reagent (4)
- # reitit (1)
- # remote-jobs (1)
- # shadow-cljs (24)
- # spacemacs (1)
- # sql (39)
- # tools-deps (10)
- # tree-sitter (18)
- # xtdb (18)
Hello I have a system
(let [system (-> (component/system-map
::rest1 (->Http)
::db1 (->Sql))
(component/system-using
{::rest1 {:db ::db1}}))]
(component/start-system system [::rest1]))
When I call it, it start rest1
without db
Is it expected? There is some way to "resolve deps" before start?@souenzzo Why are you calling that helper function (`start-system`)? All the examples/documentation show to call component/start
instead.
That aside, How is your Http
component defined?
It looks a little odd to me to see a mix of qualified and unqualified keys here...
start-system without any component names is a a synonym for calling components/start on a system
Yeah, just looked at the source -- I'd never seen anyone calling start-system
or stop-system
directly.
so by passing in component names you are overriding the automatic dependency starting logic
Makes sense. Only the whole system knows about the dependency from ::rest1
to :db
right? Could you do (component/using (->Http) {:db ::db1})
instead of (->Http)
to be able to start ::rest1
on its own with ::db1
started and injected?
I thought that component
has "lazy" capabilities to handle cases like
(let [system (-> (component/system-map
::rest1 (->Http)
::db1 (->Sql)
::rest2 (->Http))
(component/system-using
{::rest1 {:db ::db1}
::rest2 {:db ::db1}}))]
(component/start-system system [::rest1]))
Where when I ask ::rest1 it will start just what it really need
But okay. Already Implement it at my side 🙂 May PR?Use component/start
on the whole system and it will work.
the way start-system works is it sorts the set of names (defaulting to all the names) according to dependency order and then starts each thing
so if you don't give it a name, it will not be in the list regardless of the dependency information, and will not be started
so something like
(component/start-system
sys
((fn f [sys name]
(cons name
(for [[_ n] (component/dependencies (get sys name))
i (f sys n)]
i)))
system
::rest1))
Maybe I will do a ubercomponent
lib
(let [system (-> (component/system-map
::rest1 (my-comp {::id :rest1})
::rest2 (my-comp {::id :rest2})
::gql (my-comp {::id :gql})
::db1 (my-comp {::id :db1})
::db2 (my-comp {::id :db2}))
(component/system-using
{::rest1 {:db ::db1}
::rest2 {:db ::db2}
::db2 {:db ::db1}
::gql {:db1 ::db1
:db2 ::db2}}))
inits (for [[from component] system
:let [edges (component/dependencies component)]
[label to] edges
inits [[from {:label (pr-str from)}]
[to {:label (pr-str to)}]
[from
to
{:label (pr-str label)}]]]
inits)]
(-> (apply uber/digraph inits)
(doto (uber/viz-graph))
(uber.alg/topsort ::rest2)))