Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
;; -*- mode: clojure; -*-
: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"]])
'[adzerk.boot-cljs :refer :all]
'[adzerk.boot-cljs-repl :refer :all]
'[adzerk.boot-reload :refer :all]
'[cider.nrepl :refer [cider-middleware]]
'[manager.main :as app])
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 (map resolve cider-middleware)
:server true)
(deftask dev
"Develop with clojurescript."
(comp (watch)
(deftask uberjar
"Create an uberjar."
(comp (cljs)
(deftask run
"Run the app."
(comp (speak)
(app/-main []))))
(ns manager.main
[taoensso.timbre :refer [info]]
[clojure.pprint :refer [pprint]]
[ring.util.response :refer [resource-response]]
[org.httpkit.server :as httpd])
(defn- make-app
(fn [request]
(= (:uri request) "/")
(resource-response "index.html")
(resource-response (:uri request)))))
;; HTTPD concerns
(defn start-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!
(when-let [s @httpd]
(reset! httpd nil))
(defn make-httpd
(atom nil))
;; Application Bootstrap Concerns
(defn- hook-shutdown!
(doto (Runtime/getRuntime)
(.addShutdownHook (Thread. f))))
(defn- boot!
(info "Booting system.")
(let [httpd (make-httpd)]
(swap! system assoc :httpd httpd)
(start-httpd! httpd)))
(defn- crash!
(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)
(System/exit 0)))

This comment has been minimized.

Copy link

micha commented Nov 15, 2014

(deftask run
  "Start the server in a background thread."
  (let [start (delay (future (app/-main [])))]
    (with-pre-wrap @start)))
(deftask run
  "Start the server in a background thread (possibly fubar)."
  (let [start (delay (app/-main []))
        server (atom nil)]
    (cleanup (@server))
    (with-pre-wrap (reset! server @start))))
(deftask dev
  "Develop with clojurescript."
  (comp (watch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.