mount

ido 2016-04-25T12:00:53.000108Z

hey guys- I am a little confused from reading the documentation. lets say that in production I would like to restart a DB connection that is a mount state.

ido 2016-04-25T12:02:42.000109Z

how do I do this? will calling (mount/stop #'app.db/conn) + (mount/start #'app.db/conn) do the job?

tolitius 2016-04-25T13:19:00.000111Z

@ido, yep, this is exactly how you would do it

tolitius 2016-04-25T13:19:14.000112Z

given that you are ok with any ongoing transactions to fail

dm3 2016-04-25T13:20:22.000114Z

will this restart things with the conn as the dependency?

tolitius 2016-04-25T13:23:47.000115Z

@dm3: no, it will just restart conn with plugging its deps (i.e. config) back in. but it won't follow the graph to restart other depending states. so if you refer to conn as a var, you should be good. if you closed over this conn, this would be stale.

dm3 2016-04-25T13:25:03.000116Z

like if you have

(defstate a 1)
(defstate b :start (+ a 1))

dm3 2016-04-25T13:25:38.000117Z

does this magically hoist a as a ref? don't think so

dm3 2016-04-25T13:26:39.000118Z

just closes over, right?

tolitius 2016-04-25T13:27:53.000119Z

well.. just restarting a in the case above won't work (for updating b)

tolitius 2016-04-25T13:28:25.000120Z

since b after its :start is called simply becomes a Long

tolitius 2016-04-25T13:28:30.000121Z

i.e. 2

tolitius 2016-04-25T13:28:50.000122Z

so it would not rerun its :start function after a is restarted

dm3 2016-04-25T13:29:34.000124Z

that's what I expected :simple_smile: wasn't sure it's not doing some magic like https://github.com/hoplon/javelin/blob/master/src/javelin/core.clj

dm3 2016-04-25T13:30:04.000126Z

would be an overkill

tolitius 2016-04-25T13:32:47.000127Z

no, mount just creates and lets go really. I generally restart things like web servers (or other things that are usually not plugged in anywhere) at runtime. to restart a db connection would be something a bit more involved I would think (just from the use case perspective). but in case it is needed, something like:

(mount/stop #'foo/a #'bar/b #'baz/db)
(mount/start #'foo/a #'bar/b #'baz/db)
can be crafted to handle use cases like it

tolitius 2016-04-25T13:33:47.000128Z

where a and b had db injected in their :start and would need to be restarted along with db

tolitius 2016-04-25T13:36:37.000129Z

@ido: when would you want to restart conn at runtime? (just curious, maybe we can think of something to make it easier: i.e. suggest/log what could be effected if you restart a single state, or something along those lines)

ido 2016-04-25T18:21:34.000132Z

@tolitius: sometimes hardware fails. since this a vast key-value cluster, I have no transactions to care about. When I have a faulty driver, sometimes this is a quick work-around. And you know how it is: the temporary of today is the legacy of tomorrow.

ido 2016-04-25T18:24:03.000133Z

@tolitius: and since in this case the DB is stateless- restarting only this state is enough. I really need to rewrite couch-base driver in clojure. maybe we will open source it.

tolitius 2016-04-25T18:29:57.000134Z

@ido: ah.. sure. if you are certain other states are not directly closing over as in the example above with a and b, you can simply restart it by (mount/stop #'app.db/conn) / (mount/start #'app.db/conn)

ido 2016-04-25T18:34:54.000136Z

@tolitius: ok thanks!

tolitius 2016-04-25T18:58:13.000137Z

@ido: sure, thanks for asking in the first place vs. assuming. I like collecting "one off" usage cases. helps with understanding how mount is used and what I can add to make it better