Fork me on GitHub
#integrant
<
2023-03-07
>
dgb2311:03:34

I'm looking for ways to to manage application state that will change during runtime based on certain triggers like: - recreating/recompiling ring handlers with reitit - recreating temporary databases - flushing and rebuilding file/memory caches I'm looking at both mount and integrant to achieve this. I really like integrant so far. It even has an API for doing this (with examples!) with suspend/resume. The README warns us like so: &gt; Note that we only need to go to this additional effort if retaining open resources is useful during development, otherwise we can rely on the default init and halt! behavior. In production, it's always better to terminate and restart. I could also just use other patterns. Like passing around functions that dereference the current state of the above things instead of using suspend/resume. But at the same time it seems like suspend/resume does what I need, judging from the examples.

chrisetheridge11:03:58

will all of these triggers happen during development time?

dgb2311:03:10

No, in production as well.

dgb2311:03:31

my ring handler is stateful, gets recreated/changed during runtime

dgb2311:03:52

I have a temporary database that gets destroyed and recreated during runtime somewhat frequently

chrisetheridge11:03:08

ah okay, i see. what we do in this instance is just restart all systems, by calling halt! and then prep + init . our system startup is fast enough that this is a pretty good enough solution that may not suit the runtime situation you have, if you want other systems to be available during the recreation of system state

dgb2311:03:16

I could pass a (fn [_] @some-state) instead

dgb2311:03:44

I need to maintain some websocket connections during all of this so I might not use a full restart

chrisetheridge11:03:33

ah yeah no then full restart won’t work sadly. suspend + resume will work, just takes a tiny bit more thought than the brute force restart approach 😄

dgb2311:03:49

but thinking about it, I actually should first test your suggestion. It seems more sane.

chrisetheridge11:03:20

its a lot simpler, but also our systems are pretty vanilla. some web handlers and a connection to Datomic. nothing too special

dgb2311:03:20

I can recreate the connections as well, and look how reliable/fast that might be

chrisetheridge11:03:15

its nice because you can use the ‘restart’ workflow both locally and in production. its also great for local, when you want to reset the world but don’t want to wait for JVM startup

dgb2311:03:06

thank you for the advice. I might actually have to try the different approaches and see what each gives me!

chrisetheridge11:03:28

sure thing. feel free to ask for anything else. we’ve gone pretty far with Integrant, and are really happy with the lib and what we can do with it

🙏 2