Mike Meyer <mwm-keyword-googlegroups.620...@mired.org> writes: > My simple web app > (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has > some stuff that needs to happen just once (in this case, opening the > serial port). It's not clear how to get this to happen using ring. If > I do it inside my ring handler, then it gets run on every request, and > I have to check to make sure it's not run multiple times.
I would just open it lazily on the first request. That gives you a nice place to gracefully retry on error as well, instead of being dead until the entire servlet container is restarted. As a sysadmin I really hate apps that can get stuck in a error state and need restarting. ;-) For example you could be using a USB to Serial adapter, which somebody might have temporarily removed and plugged in later. Similarly if you're opening a database connection on startup and there's a network dropout, or perhaps your app got started before the database server did... > If I run it outside the handler, then it gets run when I do "lein > uberwar", which is simply wrong. If you really want to do it at load time you can avoid executing something at compile time by wrapping it in this: (when-not *compile-files* ...) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en