Fork me on GitHub
#duct
<
2018-05-04
>
eoliphant14:05:41

Hi, Im playing around with a duct project and I’m trying to understand an integrant error i’m getting. In my main.clj, where duct is doing the read/prep/exct stuff, I’ve required a datomic module I wrote, in this case, the multimethod isn’t found. However, If I move the require into say one of my handlers, it works fine. This is a little confusing as I thought the requires, should be loaded/resolved before the actual code in the namespace starts to do its thing

dadair16:05:27

@eoliphant can you post some example code?

dadair16:05:44

Might be easier to help

eoliphant16:05:21

sure

(ns gs2-grant-infra.main
  (:gen-class)
  (:require [ :as io]
            [gs2-grant-infra.modules.datomic]
            [duct.core :as duct]))

(duct/load-hierarchy)

(defn -main [& args]
  (print "starting")
  (let [keys (or (duct/parse-keys args) [:duct/daemon])]
    (-> (duct/read-config (io/resource "gs2_grant_infra/config.edn"))
        (duct/prep keys)
        (duct/exec keys))))
That’s the ‘normal’ main, plus my module require When I do a (dev), then (go), I get the No method in multimethod 'init-key' for dispatch value: :datomic/connection , However if I then do a (reset) it’s fine

dadair16:05:01

What does your config.edn look like?

eoliphant16:05:37

also pretty vanilla at this point

{:duct.core/project-ns
 gs2-grant-infra
 :duct.core/environment
 :production

 :duct.module/logging
 {}
 :duct.module.web/api
 {}

 :duct.module/ataraxy
 {[:get "/example"]  [:example]
  [:post "/command" {body :body-params}] [:command body]}

 :gs2-grant-infra.handler/example
 {}
 :gs2-grant-infra.handler/command
 {:conn #ig/ref :datomic/connection}
 :datomic/connection
 {:datomic/mode :peer
  :datomic/uri "datomic:}}
                                                              

dadair16:05:51

Well main.clj isn’t involved when you start with (dev) (go)

eoliphant16:05:04

that’s right

dadair16:05:07

You may need to add your require to dev.clj

eoliphant16:05:49

or do the load-namespaces thing somewhere

eoliphant16:05:00

but I guess that also would need to go in both places

dadair16:05:40

Yeah, you’ll need to be explicit somewhere. The easiest “automatic” way is to have the key match a proper namespace. So like g2-grant-infra.datomic and then in there have a key for ::connection

dadair16:05:12

Then use g2-grant-infra.datomic/connection as your config key

eoliphant16:05:51

ok will try that, once it’s all working, was going to refactor that out to it’s own lib, but can just update the key at that point

eoliphant16:05:53

i also have a ‘philosophical’ lol, duct question. So I have a ‘command’ handler, thats accepting POSTS, that would in turn be dispatched off to handlers based on their type field. I was just going to do this with multimethods, but now I’m wondering if it might be useful to somehow wire all that up with duct as well

dadair23:05:29

I have something like that, it’s an internal routing table defined in the config that’s passed to the “command” handler

dadair23:05:49

I’m using pedestal so I end up just enqueueing interceptors for that internal route

dadair23:05:31

I like pushing stuff into config cause there’s cool admin/tooling utilities you can build by parsing the map

dadair23:05:01

E.g., display the hierarchical routing as a topology graph, etc