mount

2024-11-21T15:35:25.296069Z

Good morning! Is there a recommended way to define a stateful thing with mount when in dev and define it without mount while in prod? This is about the best I can come up with, but it's obviously poor practice to use def within an if:

(if (= env :local)

  ;; defines conn with mount/defstate to make it easily reloadable
  (mount/defstate conn
    :start  (d/connect db-url)
    :stop (d/release conn))

  ;; defines con just as a top-level variable for use in prod
  (def conn (d/connect db-url)))

2024-11-21T15:37:29.490759Z

Or is this even something I should be bothering with? I'm coming from the standpoint that this is a development tool and shouldn't be used in prod, but maybe that's a misconception.

Jan K 2024-11-21T16:00:26.326629Z

There is no reason to avoid using mount in prod. It's definitely not meant as a dev-only tool.

tolitius 2024-11-21T16:54:05.430509Z

@andyfry01 what would be the reason not to do this for all envs?

(defstate conn :start  (d/connect db-url)
               :stop (d/release conn))

2024-11-21T19:08:20.636259Z

I .... uh, don't know 😂 @tolitius What I'm using it for right now is to reset DB connections when I need to throw away and re-bootsteap a DB. That need is what brought me to mount, and at least right now I don't know what I'd use it for in production, or what I'd need it for. I'm sure I'll discover that utility soon though. Thanks for the clarifications.

👍 1