Fork me on GitHub
#mount
<
2016-04-25
>
ido12:04:53

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.

ido12:04:42

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

tolitius13:04:00

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

tolitius13:04:14

given that you are ok with any ongoing transactions to fail

dm313:04:22

will this restart things with the conn as the dependency?

tolitius13:04:47

@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.

dm313:04:03

like if you have

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

dm313:04:38

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

dm313:04:39

just closes over, right?

tolitius13:04:53

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

tolitius13:04:25

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

tolitius13:04:50

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

dm313:04:34

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

dm313:04:04

would be an overkill

tolitius13:04:47

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

tolitius13:04:47

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

tolitius13:04:37

@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)

ido18:04:34

@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.

ido18:04:03

@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.

tolitius18:04:57

@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)

tolitius18:04:13

@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