component

scottbessler 2016-04-21T05:38:38.000008Z

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:

scottbessler 2016-04-21T05:38:44.000010Z

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

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

scottbessler 2016-04-21T05:39:37.000012Z

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)

scottbessler 2016-04-21T05:39:59.000013Z

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

sveri 2016-04-21T09:34:35.000014Z

@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

roberto 2016-04-21T13:25:14.000015Z

wrap your db in a component

roberto 2016-04-21T13:25:37.000016Z

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

2016-04-21T18:15:47.000018Z

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?

stuartsierra 2016-04-21T19:04:42.000020Z

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

stuartsierra 2016-04-21T19:05:06.000021Z

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

stuartsierra 2016-04-21T19:05:24.000022Z

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

2016-04-21T19:07:10.000023Z

thanks for the feedback, that makes a bunch of sense