This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-26
Channels
- # ai (1)
- # announcements (7)
- # babashka (2)
- # beginners (23)
- # biff (3)
- # calva (1)
- # chlorine-clover (3)
- # cider (2)
- # clj-kondo (12)
- # clojure (25)
- # clojure-brasil (4)
- # clojure-europe (33)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (1)
- # clojurescript (30)
- # clr (6)
- # consulting (1)
- # cursive (14)
- # data-science (1)
- # datalevin (4)
- # datomic (3)
- # events (4)
- # graphql (1)
- # gratitude (2)
- # hoplon (10)
- # inf-clojure (3)
- # interceptors (1)
- # introduce-yourself (1)
- # off-topic (13)
- # pathom (2)
- # pedestal (12)
- # rdf (14)
- # releases (6)
- # sci (17)
- # shadow-cljs (12)
How can I achieve ""hot reloading"", or just loading, for interceptors running in REPL? I was following this http://pedestal.io/guides/live-repl#_starting_point to achieve routes reloading, but now I am struggling on interceptors. I tried using
and clojure.tools.namespace.repl
but I'm not understanding some things I will describe better on the thread.
I first tried using clojure.tools.namespace.repl
with a functions to restart my component system, using component.repl also:
(defn restart-system []
(stop)
(set-refresh-dirs "src/")
(set-init get-system)
(refresh)
(start))
But changing an interceptor and restarting the system did not worked. The old code keeps it there.I managed to work adding
using dev/watch
before my http server is created and started. But for this work I need to manually load interceptor files and restart the system to modifications appear.
Is there a better way for doing this? I don't know clojure so much to make an approach similar to interactive routing docs, but I'm wondering if it's possible and is the better way to do so.
Hot (or warm?) reloading is kind of orthogonal to Pedestal. Pedestal interceptors are a slightly resistant pattern because (like all well-managed run-time data) the interceptor chain is data held in closure by a long-running function, which reloading does not interrupt. A workaround is for your interceptors to delegate immediately to plain functions, which (require...:reload) redefines.
@U2J4FRT2T for routing I followed the doc
::http/routes (if (= :prod env)
routes/routes
#(route/expand-routes (deref (var routes/routes))))
Changing code from interceptor is the troubleWhere are you using the interceptors? Before or after the router? The interceptors before the router will only change after a server restart. It should not be a issue once they do not change a lot.
(cond-> {:env env
::http/routes (if (= :prod env)
routes/routes
#(route/expand-routes (deref (var routes/routes))))
::http/type :jetty
::http/port 8890
::http/join? false}
true http/default-interceptors
;;true http/dev-interceptors
true interceptors/apply-interceptors
true http/create-server
(not= env :test) http/start
true ((partial assoc this :service)))
Something like this, interceptors/apply-interceptors is like this:
(defn conj-interceptor [service-map interceptor]
(update service-map ::http/interceptors conj interceptor))
(defn apply-interceptors [service-map]
(-> service-map
(conj-interceptor authentication-interceptor)))
I think I found what may be my problem, but not sure yet. I am using helper functions and import with alias but this is a warning inhttps://github.com/clojure/tools.namespace#warnings-for-helper-functions.
The problem is that I was setting (set-refresh-dirs "src/")
and when I used refresh
I actually was not reloading my user namespace (under dev/user.clj). I could debug this by adding keys to my component system map and even after refresh they did not appear.
I assumed that if they didn't appear is because my system map is not reloading, so my interceptors wouldn't reload either. 🙂
@U0HG4EHMH using :reload worked exactly as expected, loading my required file "hot reloads" interceptor. Using it have any consequences on production builded code? Just to make sure I'm not using an workaround that is actually not recommended