integrant

Eric Ihli 2020-10-26T22:12:59.026700Z

Anyone have a link to a working example of reloading the handlers of a router? Having a hard time tracking down why what I have isn't working. https://gist.github.com/eihli/caf8ef17c1e489ba7c38e09367bde51b A full example is in that gist. But the relevant integrant bits are here:

(def routes
  [["/" {:name ::home
         :get {:handler home-handler}}]])

(def config
  {:app/handler {:router (ig/ref :app/router)}
   :app/router {:routes routes}
   :app/server {:port 8000 :handler (ig/ref :app/handler)}})

(defmethod ig/init-key :app/router [_ {:keys [routes]}]
  (http/router routes))

(defmethod ig/init-key :app/handler [_ {:keys [router]}]
  (http/ring-handler router {:executor sieppari/executor}))

(defmethod ig/init-key :app/server [_ opts]
  (timbre/info "Starting server with " opts)
  (kit/run-server (:handler opts) (dissoc opts :handler)))

(defmethod ig/halt-key! :app/server [_ server]
  (timbre/info "Stopping server")
  (server))
I'm using Cider and I have cider-ns-refresh-before-fn set to intergrant.repl/halt and it appears to be working. But when I refresh localhost:8000, I don't see the updates that I make to the home-handler from the above gist.
((nil . ((cider-ns-refresh-before-fn . "integrant.repl/halt")
         (cider-ns-refresh-after-fn . "integrant.repl/init"))))
Below is the output of cider-ns-refresh. It's detecting the changed namespaces, says it's reloading them, successfully starts the server, but when I visit it, no change.
Calling integrant.repl/halt
2020-10-26T22:07:40.616Z Glacius INFO [com.darklimericks.server.example:46] - Stopping server
Successfully called integrant.repl/halt
Reloading (com.darklimericks.server.core user.core com.darklimericks.server.example user)
Reloading successful
Calling integrant.repl/init
2020-10-26T22:07:40.708Z Glacius INFO [com.darklimericks.server.example:42] - Starting server with  {:port 8000, :handler #function[clojure.lang.AFunction/1]}
Successfully called integrant.repl/init

Eric Ihli 2020-10-26T22:25:54.028400Z

Well... aside from the above workflow not working the way I expect, I think I at least found another way. I see duct uses hawk to watch for changes and automatically call integrant.repl/reset. So I'll do that for now. https://github.com/duct-framework/core/blob/master/src/duct/core/repl.clj