Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 268
konr Avatar asked Dec 20 '12 18:12

konr


1 Answers

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

like image 117
ponzao Avatar answered Oct 18 '22 23:10

ponzao