Fork me on GitHub
#biff
<
2022-11-07
>
licht1stein10:11:16

Hi guys! I'm trying to integrate biff as a base into a polylith project. Did anyone try to do this?

licht1stein14:11:30

Namely, I would like to decouple the xtdb node from starting the entire biff system. How can I pass an existing node on startup?

Jacob O'Bryant18:11:47

Hi! I haven't used polylith at all myself. But to pass in a node yourself, you'll need to remove the biff/use-xt component and then include a :biff.xtdb/node key in the map that you pass to biff/start-system . You'll also probably want to include a stop fn for the node (in the :biff/stop key) so that biff/refresh works.

(defn start-xtdb-node []
  ...)

(def components
  [biff/use-config
   biff/use-random-default-secrets
   ;biff/use-xt
   biff/use-queues
   biff/use-tx-listener
   biff/use-outer-default-middleware
   biff/use-jetty
   biff/use-chime
   (biff/use-when
    :com.example/enable-beholder
    biff/use-beholder)])

(defn start []
  (let [node (start-xtdb-node)]
    (biff/start-system
     {:biff.xtdb/node node
      :biff/stop (list #(.close node))
      ...}))
  ...)

licht1stein18:11:24

Thanks, I will try it out!

licht1stein19:11:17

I also need to decouple the config files location, is there a similar way to do that?

Jacob O'Bryant19:11:44

Yep, there's a :biff/config "config.edn" line in that map which you can change. If you want to use a different config format altogether, you can remove the biff/use-config component and replace it with your own code.

licht1stein19:11:29

I will let you know as soon as I can try

Jacob O'Bryant19:11:47

You're welcome!

licht1stein21:11:48

@U7YNGKDHA It's kind of working with a custom config and my own node, but I get this error when trying to log into the example app:

[qtp424628542-31] INFO com.biffweb.impl.middleware -  31ms 303 post /auth/send
[qtp424628542-37] INFO com.biffweb.impl.middleware -   2ms 200 get  /auth/printed/
[qtp424628542-36] ERROR com.biffweb.impl.middleware - Exception while handling request
clojure.lang.ExceptionInfo: Transaction violated a constraint {:tx ([:xtdb.api/match #uuid "4ce0c68d-6523-4737-bca8-56ed29752cf3" nil] [:xtdb.api/put {:user/joined-at #inst "2022-11-07T21:44:07.494-00:00", :user/email "", :xt/id #uuid "4ce0c68d-6523-4737-bca8-56ed29752cf3"}] [:xtdb.api/fn :biff/ensure-unique {:user/email ""}])}

Jacob O'Bryant23:11:09

Oh, I forgot that the use-xt component also adds a transaction function to database on startup, which is used for uniqueness constraints. not at my computer atm, but you can look at the source of biff/use-xt and copy over the tx fn part.

Jacob O'Bryant23:11:39

basically call this function: https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L470 with biff/tx-fns as the parameter

1
macrobartfast23:11:37

Necropost Alert! @U01V67SBM55 did you end up integrating Biff into Polylith in some fashion?