Search code examples
clojurecompojurering

How to run an arbitrary startup function in a ring project?


I've got a compojure/ring application I currently run with lein ring server that I'd like to compile to a .war so I can deploy it. I've got a definition, however, just like

 (def foo (start-scheduler))

That blocks the compilation and the generation of the .war. To circumvent this, I thought about moving the call to a startup function, but how would I call it when the server launches?

If I put the call inside the handler, I'd end up with the same problem as before.

Thanks!


Solution

  • In your project.clj when declaring your Ring handler you can also specify an init (and destroy) function that is run when your application starts:

    :ring {:init myproject.core/init
           :destroy myproject.core/destroy
           :handler myproject.core/handler}
    

    This is documented here: https://github.com/weavejester/lein-ring#general-options