component

devth 2017-07-04T16:51:05.814458Z

can I stop/start a single component that's part of a larger system and expect it to propagate to the other components that depend on it?

devth 2017-07-04T16:51:15.816742Z

seems that is not the case. not sure if i need to re-construct the entire system

2017-07-04T16:56:23.882753Z

@devth No, that's not a supported use case.

2017-07-04T16:56:39.885919Z

each part of the system is meant to be immutable, which means restarting foo means restarting transitively everything that uses foo

2017-07-04T16:57:06.891248Z

Operations happen over the entire system. You can manually traverse the system with update-system if you wish.

👍 1
2017-07-04T16:57:08.891740Z

(but maybe you could get away with not restarting the things foo uses - maybe hack?)

2017-07-04T16:58:36.910239Z

You can also look at how things in component are implemented (see tools.namespace), and traverse the graph yourself.

devth 2017-07-04T16:58:52.913487Z

ok. i could probably reset the entire system

2017-07-04T16:58:59.915016Z

But know that it's conceptually much more difficult to manage than just restarting the entire system.

2017-07-04T17:00:26.934731Z

The only downside I see there is speed. If for some reason cycling some particular component is slow, it might need to be avoided. But I have yet to have a system restart that takes longer than a second (and I have some pretty big systems).

devth 2017-07-04T17:00:53.940936Z

cool. in this case i need to reset a released Datomic connection. other components in the system are the web server and an elasticsearch connection

devth 2017-07-04T17:00:58.941879Z

probably cleanest to restart the entire system

2017-07-04T17:03:49.979011Z

You know what? I don't even release my datomic conns on system restart. I forgot that fn even existed.

2017-07-04T17:05:24.998555Z

Datomic is kind of a special animal IMO. It's inherently tied to the lifecycle of the VM (via agents).

2017-07-04T17:05:44.002729Z

And you can look up connections via URI at will.

2017-07-04T17:05:57.005142Z

So there's not a lot of advantage for managing connection passing yourself.

devth 2017-07-04T17:06:04.006490Z

the problem is sometimes during dev i need to recreate the database, which releases the connection

devth 2017-07-04T17:06:10.007554Z

i want to do this without restarting my entire jvm/repl

2017-07-04T17:07:02.017915Z

you can restart a system without restarting either jvm or repl

devth 2017-07-04T17:07:14.020373Z

right - that's what i'm aiming to do 🙂

devth 2017-07-04T17:07:26.022668Z

but my first stab was to think about only restarting the datomic sub-component

2017-07-04T17:07:26.022714Z

yeah, you can easily do that with the whole system

2017-07-04T17:07:27.022996Z

Manually call (d/delete-database uri) (d/create-database uri)?

2017-07-04T17:07:30.023415Z

just stop it then start it

devth 2017-07-04T17:07:51.027519Z

@potetm yep, but the connection stored in the db component will be released when i do that

2017-07-04T17:08:04.030031Z

Yeah don't store the conn in a component.

2017-07-04T17:08:10.031116Z

Is what I'm saying.

devth 2017-07-04T17:08:18.032664Z

oh really

2017-07-04T17:08:41.037120Z

I find that relationship awkward, especially considering datomic has its own resources it manages anyways.

devth 2017-07-04T17:08:59.040676Z

you store the db-uri in the component and d/connect anywhere you need a conn?

2017-07-04T17:09:11.043059Z

I do have a datomic component in my system, but I have multiple databases, and must dispatch on a value other than the URI.

2017-07-04T17:09:28.046761Z

Yeah that would work perfect.

2017-07-04T17:09:56.052591Z

Or you create a component that wraps anything that uses a URI if you want to make the URI opaque.

2017-07-04T17:10:09.055285Z

But no need to release connections.

devth 2017-07-04T17:10:48.063764Z

maybe i'll store a thunk that creates a conn in the db component

2017-07-04T17:11:02.066488Z

Conceptually the URI is a dispatch value to a connection.

devth 2017-07-04T17:11:04.066847Z

i only have 1 db-uri

devth 2017-07-04T17:11:08.067427Z

(currently)

2017-07-04T17:11:30.071811Z

you can implement IFn for a defrecord so your component could be the thunk

devth 2017-07-04T17:11:42.074285Z

oh cool

2017-07-04T17:12:00.077604Z

And those connections are already managed for you.

2017-07-04T17:12:20.081683Z

So no need to take over something that Datomic has already agreed to do correctly. Just pass the dispatch value.

devth 2017-07-04T17:12:30.083721Z

right

2017-07-04T17:14:21.104341Z

(I fought this battle for a while. I really wanted to do a full restart via d/shutdown. After a while, I found that with datomic and core.async it's better to let them live tied to the VM and not try to manage them via component.)

devth 2017-07-04T17:14:35.107151Z

good to know. thanks!