I have a system and I want to restart some keys and also the ones depending on these keys. How do I do that?
yes
It’s very simple. I have a running system. A namespace, where ig/init-key defmethod is defined, is reloaded. I want to restart (or better suspend/resume) that key in my system and all keys that depend on it. I would like to avoid doing this with whole system. It seems pretty hard to do this with the current implementation of suspend/resume mechanic.
Also another hurdle there is when I use a refset, it will not even try to suspend the component that uses the reloaded key via a refset. Seems like refset acts like a blocker when traversing depenency graph looking for ancestors.
Integrant allows for starting a subset of a configuration, but not restarting a subset of what was started. You mention that you want to avoid restarting the whole system, but in order to fully understand your use-case I need to know why you want to avoid restarting the system.
Awkward why? You'll need to explain your use-case. From what I gather you're starting a system with one set of keys, then trying to restart only a subset of those keys? To what end?
If you supply a list of keys to init, only those keys and their dependencies will be started. Is that what you mean?
Well it’s the standard dev loop. I have a file watcher which triggers namespace reloads. After namespace reloads, I look at (methods ig/init-key and detect changes there to see which components need to be replaced in the system. This is where I want to limit the suspend/resume to just the minimum number of components needed. After that I also notify all connected clients via websocket to reload the page (typically 1-2 tabs open on dev machine).
So this works really well, but there’s a critical dimension here, which is the delay. When I save a file I get new version of the page loaded in about 0.5 sec, which is good enough to not be too disruptive. But as the system I am restarting gets larger, the time it takes to restart it all is longer. Here’s where I’d prefer to limit the amount of work done, when a very simple component is changed and I don’t want to restart my DB connection pool over that.
Integrant takes the view that it's always better to restart the entire system whenever possible, as that reduces the chance that your system gets into an invalid state. The suspend/resume methods are included as a compromise - keys that take a while to halt or init can implement the suspend/resume methods in order to avoid expensive restarts, or to keep connections to a client open. For example, if you don't want to restart your DB connection pool each time, then you can write a resume method that checks to see if the options are the same, and if so reuse the existing pool. This isn't to say that your suggested approach has no merit; it might be that this is something we want to add to Integrant in future. However, there needs to be a clear use-case for this. In other words, it needs to be something that suspend/resume cannot easily handle.
Ok so I wrote some code that calls ig/suspend! with a list of keys and then ig/resume with same keys. The issue is that ig/resume will halt all keys that are not in the list of keys it’s given. Is there any way around that? It’s a very awkward design.