Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Last active December 22, 2015 12:39
Show Gist options
  • Save martintrojer/6473714 to your computer and use it in GitHub Desktop.
Save martintrojer/6473714 to your computer and use it in GitHub Desktop.
reloaded
(ns app
(:gen-class))
(defn -main [& args]
(require 'myapp.core)
(eval `(apply myapp.core/old-main ~args)))
(defrecord JettyServer [cfg state]
LifeCycle
(start [_]
(reset! state (jetty/run-jetty my-site {:port (:port cfg) :join? false}))
(stop [_]
(when @state
(.stop @state)
(reset! state nil))))
(defn create-jetty [cfg]
(->JettyServer cfg (atom nil)))
(ns lifecycle)
(defprotocol LifeCycle
(start [this])
(stop [this]))
(defn start-system [system]
(doseq [s (->> system :order (map system))]
(start s)))
(defn stop-system [system]
(doseq [s (->> system :order (map system) reverse)]
(stop s)))
(defn create-system [cfg]
{:jetty (create-jetty-server cfg)
:rabbit (create-rabbitmq-channel cfg)
:order [:rabbit :jetty])
(defn app-main []
(let [cfg (config/create-config)
system (create-system cfg)]
(start-system system)
;; (.await) / (.join) / (deref) etc...
(stop-system system)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment