Fork me on GitHub
#component
<
2016-04-21
>
scottbessler05:04:38

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:

scottbessler05:04:44

(def ^:dynamic *db*
  (:db system))

(conman/bind-connection *db* "stridespark/api/queries_hug.sql")

scottbessler05:04:37

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)

scottbessler05:04:59

so, whats the idiomatic way to do this in system?

sveri09:04:35

@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

roberto13:04:14

wrap your db in a component

roberto13:04:37

and pass it in as a dependency to the components that need it

mss18:04:47

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?

Lambda/Sierra19:04:42

@mss Yes, the JVM will exit as soon as the main method returns.

Lambda/Sierra19:04:06

If you want it to stick around, you need to "join" your main thread on to one of the threads started by your components.

Lambda/Sierra19:04:24

Or have the main thread block, waiting for some indication that it is ready to shut down.

mss19:04:10

thanks for the feedback, that makes a bunch of sense