Comments (9)
Basically, if I'm understanding correctly by the time
.contextDestroyed
has been called, it's too late to do anything meaningful - even something as trivial as logging.
Sorry, I'm afraid I'm not following. Why does the listener function care whether or not the servlet exists? It's just a shim for the handler.
from lein-ring.
Sorry, I'm afraid I'm not following. Why does the listener function care whether or not the servlet exists? It's just a shim for the handler.
I can't answer that with any form of confidence or authority...all I know, is that the code in our :destroy
fns doesn't run on un/re-deploy, and since Friday I also know (from the docs) that the kind of work we're doing (cleanup/persist-state) should be done in the Sevlet::destroy
method. I do have a local copy of lein-ring
(for #217), so I'm going to try and implement this today, and see what happens. Will keep you posted...
from lein-ring.
I can confirm that overriding the .destroy
method on the Servlet solves our issue - i.e. all the expected logging is now visible, and each component's state is persisted as well. Here is the modified compile-servlet
:
(defn compile-servlet [project]
(let [servlet-ns (symbol (servlet-ns project))
destroy-sym (get-in project [:ring :destroy])]
(compile-form project servlet-ns
`(do (ns ~servlet-ns
(:gen-class
:extends javax.servlet.http.HttpServlet
:exposes-methods {~'destroy ~'superDestroy}) ;; <===
(:import javax.servlet.http.HttpServlet))
(def ~'service-method)
(defn ~'-service [servlet# request# response#]
(~'service-method servlet# request# response#))
(defn ~'-destroy [this#] ;; <===
~(if destroy-sym
`(~(generate-resolve destroy-sym)))
(. this# ~'superDestroy))) ;; <===
:print-meta true)))
I guess, in an ideal situation lein-ring
would offer the following (self-explanatory) options:
- servlet-init
- servlet-destroy
- context-init
- context-destroyed (notice the past tense)
Since, I presume that backwards compatibility is desired, and the :init
/:destroy
keys already refer to the context, realistically the only viable option is to simply add support for :servlet-init/destroy
.
from lein-ring.
Yep, keeping compatibility is the best option. If you're having issues that are solved with overriding destroy
, then that's likely reason enough to add a couple more configuration keys to Lein-Ring to override the init
and destroy
servlet methods.
from lein-ring.
Agreed...would you like a PR? I have no problem working on it, but I would prefer that we merge #217 first.
from lein-ring.
Sure. I had 20 minutes or so spare, so it's now merged.
from lein-ring.
Great thanks 👍 . Unfortunately, because of the manual merge, the new PR I want to open shows 16 commits ahead, even though there is a single new commit and file changed (a few lines actually). Will you be ok keeping the last commit only, if I open it like that?
from lein-ring.
Why not just reset to master and cherry pick the single commit you want?
from lein-ring.
Thanks for the idea - see #219
from lein-ring.
Related Issues (20)
- tools.nrepl version added is very old HOT 7
- ensure-handler-set! incorrectly calls System/exit HOT 4
- lein ring server-headless custom-port doesn't works HOT 5
- 0.12.2 fails when compiling `:aot :all` HOT 5
- Looks like release 0.12.3 haven't actually been pushed to clojars HOT 2
- Was something package name changed? HOT 10
- :ring :nrepl :start? true injects [org.clojure/tools.nrepl "0.2.3"] which messes up CIDER, cider-nrepl and nREPL HOT 3
- Dependency `unify` broken with Clojure 1.10 HOT 5
- Problem passing jetty adapter options as :adapter map using ring by server-headless HOT 2
- CompilerError occured in Clojure1.10 HOT 1
- uberwar task fails with latest leiningen versions HOT 2
- Update ring-version to latest
- SslContextFactory$Server not found HOT 2
- how to set jvm-opts for ring task HOT 1
- :listener-class HOT 2
- :reload-paths equivalent for :auto-refresh? HOT 5
- Jar collision: duct/core VS ragtime/core HOT 15
- Async handlers work only with Jetty HOT 8
- Running lein ring server headless, ignores resources/log4j.properties HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lein-ring.