-
-
Save micha/9d54494c1d79135b1b60 to your computer and use it in GitHub Desktop.
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
;; -*- mode: clojure; -*- | |
(set-env! | |
:src-paths #{"src/clj" "src/cljs"} | |
:rsc-paths #{"resources"} | |
:update :always | |
:dependencies '[[org.clojure/clojure "1.7.0-alpha4"] | |
[org.clojure/core.async "0.1.346.0-17112a-alpha"] | |
[com.taoensso/timbre "3.3.1-1cd4b70"] | |
[http-kit "2.1.19"] | |
[ring/ring-core "1.3.1"] | |
[org.clojure/clojurescript "0.0-2371" :scope "provided"] | |
[om "0.8.0-alpha2" :scope "provided"] | |
[sablono "0.2.22" :scope "provided"] | |
[adzerk/boot-cljs "0.0-2371-25" :scope "provided"] | |
[adzerk/boot-cljs-repl "0.1.5" :scope "provided"] | |
[adzerk/boot-reload "0.1.5" :scope "provided"] | |
[cider/cider-nrepl "0.8.0-SNAPSHOT" :scope "provided"] | |
[org.clojure/tools.nrepl "0.2.6" :scope "provided"]]) | |
(require | |
'[adzerk.boot-cljs :refer :all] | |
'[adzerk.boot-cljs-repl :refer :all] | |
'[adzerk.boot-reload :refer :all] | |
'[manager.main :as app]) | |
(task-options! | |
pom [:project 'mgmt :version "1"] | |
aot [:all true] | |
jar [:file "manager.jar" :main 'manager.main] | |
uber [:exclude-scope #{"provided"}] | |
cljs [:output-to "main.js" :optimizations :whitespace :pretty-print true]) | |
(deftask emacs-repl | |
"Start an Emacs Cider REPL." | |
[] | |
(repl :middleware ['cider.nrepl/cider-middleware] | |
:server true) | |
(wait)) | |
(deftask dev | |
"Develop with clojurescript." | |
[] | |
(comp (watch) | |
(speak) | |
(cljs-repl) | |
(cljs) | |
(reload))) | |
(deftask uberjar | |
"Create an uberjar." | |
[] | |
(comp (cljs) | |
(aot) | |
(add-src) | |
(uber) | |
(jar))) | |
(deftask run | |
"Run the app." | |
[] | |
(comp (speak) | |
(cljs) | |
(with-pre-wrap | |
(app/-main [])))) |
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 manager.main | |
(:require | |
[taoensso.timbre :refer [info]] | |
[clojure.pprint :refer [pprint]] | |
[ring.util.response :refer [resource-response]] | |
[org.httpkit.server :as httpd]) | |
(:gen-class)) | |
(defn- make-app | |
[] | |
(fn [request] | |
(cond | |
(= (:uri request) "/") | |
(resource-response "index.html") | |
:else | |
(resource-response (:uri request))))) | |
;;----------------------------------------------------------------------------- | |
;; HTTPD concerns | |
(defn start-httpd! | |
[httpd] | |
(let [s (httpd/run-server (make-app) {:port 2112 | |
:worker-name-prefix "hkit-"})] | |
(info " - Running web application on http://localhost:2112.") | |
(reset! httpd s))) | |
(defn stop-httpd! | |
[httpd] | |
(when-let [s @httpd] | |
(s)) | |
(reset! httpd nil)) | |
(defn make-httpd | |
[] | |
(atom nil)) | |
;;----------------------------------------------------------------------------- | |
;; Application Bootstrap Concerns | |
(defn- hook-shutdown! | |
[f] | |
(doto (Runtime/getRuntime) | |
(.addShutdownHook (Thread. f)))) | |
(defn- boot! | |
[system] | |
(info "Booting system.") | |
(let [httpd (make-httpd)] | |
(swap! system assoc :httpd httpd) | |
(start-httpd! httpd))) | |
(defn- crash! | |
[system] | |
(info "System shutting down.") | |
(stop-httpd! (:httpd @system)) | |
(swap! system dissoc :httpd)) | |
(defonce ^:private system | |
(atom {})) | |
;;----------------------------------------------------------------------------- | |
;; Application Entry Point | |
(defn -main | |
[& args] | |
(info "Welcome to the Mgmt Application") | |
(let [lock (promise)] | |
(hook-shutdown! (fn [] (crash! system))) | |
(hook-shutdown! (fn [] (deliver lock :done))) | |
(boot! system) | |
@lock | |
(System/exit 0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment