This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-27
Channels
- # announcements (8)
- # architecture (3)
- # aws (18)
- # beginners (96)
- # bristol-clojurians (3)
- # calva (15)
- # cider (7)
- # clj-kondo (8)
- # clojure (135)
- # clojure-denmark (1)
- # clojure-dev (14)
- # clojure-europe (37)
- # clojure-italy (9)
- # clojure-nl (14)
- # clojure-sanfrancisco (1)
- # clojure-spec (1)
- # clojure-uk (54)
- # clojurescript (27)
- # core-async (243)
- # cursive (28)
- # data-science (6)
- # datomic (33)
- # fulcro (25)
- # graalvm (24)
- # hoplon (2)
- # instaparse (12)
- # jackdaw (1)
- # java (21)
- # juxt (12)
- # meander (10)
- # nyc (4)
- # off-topic (6)
- # om (3)
- # pathom (17)
- # perun (1)
- # re-frame (29)
- # reitit (4)
- # rum (3)
- # shadow-cljs (119)
- # spacemacs (31)
- # xtdb (14)
im trying to make a throw-away datomic system using juxt/clip
and try to clean up the created tmp db after stopping it.
i can't seem to figure out how can i pass a (clip/ref)
within the :stop
operation:
(defn default-schema-from-file []
(->> "datomic-schema.edn" io/resource slurp edn/read-string))
(defn tmp-in-mem-uri [] (str (gensym "datomic:-")))
(defn cleanup [uri conn]
(prn [uri conn])
(d/release conn)
(d/delete-database uri))
(defn tmp-parts []
{:datomic/schema
{:start `(default-schema-from-file)}
:datomic/uri
{:start `(tmp-in-mem-uri)}
:datomic/conn
{:pre-start `(d/create-database (clip/ref :datomic/uri))
:start `(d/connect (clip/ref :datomic/uri))
:post-start `(d/transact ~'this (clip/ref :datomic/schema))
:stop `(cleanup (clip/ref :datomic/uri) ~'this)}})
that (prn [uri conn])
debug statement prints:
[(clip/ref :datomic/uri) #object[datomic.peer.LocalConnection 0x63235b75 "datomic.peer.LocalConnection@63235b75"]]
so the ~'this
gets resolved as I expected but the (clip/ref :datomic/uri)
doesn'tyeah, i can see how it can pose unreconcilable constraints on the start/stop ordering... but in this case what shall i do? sounds like i would need to carry the dependencies of the stop process within the started component. but then will that component be still valid when im stopping the system?... 😕
or i could try to tease out this info from the connection object using something like this:
(.dbname ^datomic.peer.LocalConnection (sys :datomic/conn))
=> "tmp-17692"
i was trying to "inline" my small cleanup
function as:
:stop `(do (d/release (:conn ~'this))
(d/delete-database (:uri ~'this)))
then I got this error:
Execution error (ExceptionInfo) at juxt.clip.impl.core/evaluate-pseudo-clojure$fn (core.cljc:187).
Got null for function looking up symbol: do
this pseudo eval thing is quite fragile 😕
still no idea though how could be it done better...this feels like an ok compromise:
(defn cleanup-conn&db [{:keys [uri conn]}]
(d/release conn)
(d/delete-database uri))
(defn tmp-parts []
{:datomic/schema
{:start `(default-schema-from-file)}
:datomic/uri
{:start `(tmp-in-mem-uri)}
:datomic/conn
{:pre-start `(d/create-database (clip/ref :datomic/uri))
:start `{:uri (clip/ref :datomic/uri)
:conn (d/connect (clip/ref :datomic/uri))}
:resolve :conn
:post-start `(d/transact (:conn ~'this) (clip/ref :datomic/schema))
:stop `(cleanup-conn&db ~'this)}})
(comment
@(def sys-config {:components (tmp-parts)})
@(def sys (clip/start sys-config))
(clip/stop sys-config sys)
)
hmm... im also wondering how can i make this thing more modular, so i can create multiple datomic connections. the use-case would be to create a migration program, which transforms one datomic db into another one. but then i would need uri/schema/conn for each instance... so a started system would look something like this:
{:source-123/schema [,,,]
:source-123/uri "datomic:"
:source-123/data {:uri "datomic:"
:conn ^datomic.peer.Connection []}
:dest-234/schema [,,,]
:dest-234/uri "datomic:"
:dest-234/data {:uri "datomic:"
:conn ^datomic.peer.Connection []}}