Fork me on GitHub
#beginners
<
2018-07-15
>
valerauko18:07:31

i'm using hikari-cp to handle my database connection. i was only running it from lein locally for development so far, but now i tried to build an uberjar to test online. however, it seems to try to connect to (the "production") database host while building the jar which obviously fails. why is it doing that and how do i stop it?

mg18:07:27

@vale are you building an hikari connection pool in a def in one of your prod namespaces?

valerauko18:07:27

(def conn
  {:datasource (make-datasource options)})

mg18:07:22

Building a jar includes compilation which means evaluating top level defs

valerauko18:07:58

how would i do it then instead?

noisesmith18:07:43

it's possible (and often a good idea) to build a jar without compiling, but even so you should not have side effecting code at the top level of a namespace

noisesmith18:07:24

there's a few alternate patterns, a common robust one is a library for managing stateful things, like stuartsierra/component or integrant

noisesmith18:07:17

but even putting your connection in a delay or promise, and not forcing / realizing until later will suffice

valerauko18:07:06

all right, i guess i'll play around with integrant then

valerauko18:07:26

for reference though, how would i build a jar without compiling (the problematic namespace)?

noisesmith18:07:56

by not specifying aot, and changing your app startup to java -jar my-uber.jar clojure.main -m my.ns

noisesmith18:07:43

(plus any other args you need, of course)

kennytilton23:07:28

So I have to de-dupe a list of browsers visited and come up with this:

;; pick out most recent of visits to same URL
  (->> (vals browsers)
          (group-by :url)
          (map (fn [[_ values]]
          (first (sort-by :timestamp > values))))
          ;; now restore original structure
           (into {} (map (fn [m] [(:browser-id m) m]))
but the idea of parameterized de-duping seems reusable. Question: do good Clojurians cook up a new group-distict-by-yada-yada and wonder if it will ever get re-used, or do we just knock off these three-step transformations ad hoc and keep on trucking?

mfikes23:07:14

Certainly, distinct-by (with an arglist of [f coll]) seems to be a useful one that is often added to projects