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

99封情书 提交于 2019-11-30 01:29:26

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/13978623/how-to-run-an-arbitrary-startup-function-in-a-ring-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!