Created
June 19, 2017 19:36
-
-
Save daemianmack/3f7edb86aa6f5fd4af4722ece42fc6bb to your computer and use it in GitHub Desktop.
Wrap the dev-system
This file contains hidden or 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
;; I use this to wrap the `dev-system` in a way that... | |
;; - Alerts me when the system launch completes so I can do something | |
;; else while waiting, without getting sidetracked | |
;; - Alerts me when the system launch hangs | |
;; - Runs Eastwood | |
;; - Squelches logging from namespaces whose logging statements | |
;; frequently mask the logging I'm trying to see | |
;; I put this in ./dev and then | |
;; `printf ":/Users/daemian/src/ww/elephant/dev" >> build/cached-classpath` | |
;; (Use of Eastwood also requires the corresponding dependency.) | |
;; Not checking this in because although this can be a useful development | |
;; pattern, you can also shoot yourself in the foot. | |
(ns hack-system | |
(:require [clojure.java.shell :refer [sh]] | |
[elephant.dev-system :as ds] | |
[elephant.export.greenhouse.core :as gc] | |
[eastwood.lint :as e]) | |
(:import [org.slf4j LoggerFactory] | |
[ch.qos.logback.classic Level])) | |
(defn quiet-logging! [the-ns] | |
(.setLevel (LoggerFactory/getLogger the-ns) | |
(Level/valueOf "WARN"))) | |
(defn alert-pass [] | |
(sh "afplay" "-r" "0.5" "/System/Library/Sounds/Hero.aiff")) | |
(defn alert-fail [] | |
(sh "afplay" "-r" "0.5" "/System/Library/Sounds/Funk.aiff")) | |
(defn -main [] | |
(println :launching-hack-system) | |
(e/eastwood {:source-paths ["src/main/clj" "src/test/clj"] | |
:continue-on-exception true}) | |
(quiet-logging! "dialog-manager.core") | |
(quiet-logging! "dialog-manager.utils.goal") | |
;; Reloading ./dev code on `reset` borks system. | |
(clojure.tools.namespace.repl/set-refresh-dirs "src/main") | |
;; Start the clock on failure alert if system launch hangs. | |
(let [fail-switch (future (do (Thread/sleep 30000) | |
(alert-fail)))] | |
(try (ds/-main) | |
;; System has launched; cancel this. | |
(future-cancel fail-switch) | |
(catch Exception e | |
(prn :exception e) | |
(spit "hack-system-startup-error.txt" e) | |
(alert-fail) | |
(System/exit 1)))) | |
;; Finally, alert we're up. | |
(future (alert-pass))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment