Last active
December 22, 2015 12:39
-
-
Save martintrojer/6473714 to your computer and use it in GitHub Desktop.
reloaded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app | |
(:gen-class)) | |
(defn -main [& args] | |
(require 'myapp.core) | |
(eval `(apply myapp.core/old-main ~args))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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