This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-11
Channels
- # aws (6)
- # beginners (105)
- # boot (6)
- # cider (50)
- # cljsrn (10)
- # clojure (41)
- # clojure-brasil (6)
- # clojure-italy (25)
- # clojure-nl (17)
- # clojure-russia (4)
- # clojure-serbia (1)
- # clojure-spec (8)
- # clojure-uk (242)
- # clojurescript (27)
- # core-async (10)
- # cursive (5)
- # data-science (9)
- # datomic (43)
- # emacs (6)
- # fulcro (6)
- # graphql (1)
- # javascript (3)
- # juxt (4)
- # lein-figwheel (1)
- # mount (1)
- # onyx (19)
- # parinfer (2)
- # portkey (15)
- # protorepl (1)
- # re-frame (30)
- # reagent (3)
- # ring-swagger (1)
- # shadow-cljs (22)
- # sql (6)
- # tools-deps (23)
- # vim (13)
@seancorfield You’re probably right that I miss-read the docs. I did use with-db-connection
, but in my scenario, the connection is sometimes lost, and I’m not sure the macro handles this, right?
Anyway, a way for me to deal with this is to have an atom with a connection, and then once in a while make a new connection if the old fails.
If you or anyone else know a better strategy for this kind of resilience, I’d be very happy to know 🙂
@grav Using an atom for the connection sounds like a terrible hack to me. with-db-connection
will open the connection, run the body of the form, and then close the connection. It shouldn't get "sometimes lost" unless you have a flaky database or a flaky network?
I'd recommend reading the docs for Reusing Connections and considering a connection pool (we use c3p0 heavily at work, I've heard other folks praise Hikari, and there are a few other options).
If you use a connection pooling library, bad connections should automatically be dropped and new connections created. But if connections are going bad (due to network/DB issues) you would have to decide whether to retry a given (set of) SQL operation(s). That's true regardless, since "the network is broken", and applications all need to build in resilience somehow for failures of any external interactions.