so i was trying to use conman with system
instead of mount
but struggling on how/when to execute the bind-connection call.. currently have this:
(def ^:dynamic *db*
(:db system))
(conman/bind-connection *db* "stridespark/api/queries_hug.sql")
but this does not behave as intended (i believe i get why now, which is that db is not being rebound by system, whereas when i use mount’s defstate it is)
so, whats the idiomatic way to do this in system?
@scottbessler: I dont know anything about conman, but looking at your code snippet I see that you define a dynamic var, which should never be there in a codebase using component
wrap your db in a component
and pass it in as a dependency to the components that need it
apologies if this is a bit of a beginner question. I’m having trouble getting component to play nicely with lein startup/shutdown. I’ve created a few components that are doing some amount of async processing. they’re wrapped up in a system that’s instantiated with a main
function.
my code looks something like:
(defn -main
[& args]
(alter-var-root #’my-system component/start)
(.addShutdownHook (Runtime/getRuntime) (Thread. #(alter-var-root #’my-system component/stop))))
the services kicked off by component/start
should theoretically be running until a shutdown signal is given, but it seems that once that function returns, the jvm process is exiting immediately.
am I missing something about what’s going on under the hood here?@mss Yes, the JVM will exit as soon as the main
method returns.
If you want it to stick around, you need to "join" your main thread on to one of the threads started by your components.
Or have the main thread block, waiting for some indication that it is ready to shut down.
thanks for the feedback, that makes a bunch of sense