What is the best way to get the new code to the production ring server without restarting the entire JVM?
I currently use wrap-reload in production, but this doesnβt work for me, because sometimes I want to run commands in repl (for example, when migrating databases), before starting a call, it will start processing requests using new code. In addition, various blogs and tutorials say that reloading should not be used in the production process, although I do not understand why not.
I came up with the following solution, but I confess I do not have a deep understanding of what is happening under the hood. I was wondering if I can get a test of the performance of whoever does this. Does this method seem reasonable?
The idea is to have a path (/ admin / reload-clj) that causes all clojure code to reload.
(defonce ^:dynamic *jetty*) (declare reload-clj) (defn app [req] ... (when (= (req :uri) "/admin/reload-clj") (reload-clj req)) ...) (defn start-jetty [] (let [j (run-jetty app {:port (http-port) :join? false :max-threads 16})] (dosync (ref-set *jetty* j)) j)) (defn reload-clj [req] (future (log/info "Reloading clojure code...") (require '(whrusrv admin main utils wdb) :reload-all) (.stop @*jetty*) (start-jetty) (log/info "Clojure reload success!")) {:status 200 :headers {"Content-Type" "text/plain"} :body "Reloading..."}) (defn -main [& args] (start-jetty))
clojure ring
Aaron iba
source share