Fork me on GitHub

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.


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


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


given that you are ok with any ongoing transactions to fail


will this restart things with the conn as the dependency?


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


like if you have

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


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


just closes over, right?


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


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


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


that's what I expected simple_smile wasn't sure it's not doing some magic like


would be an overkill


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


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


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


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


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


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