Skip to content

Instantly share code, notes, and snippets.

@matstani
Created August 17, 2014 20:25
Show Gist options
  • Save matstani/4852df3eb4856bccbce4 to your computer and use it in GitHub Desktop.
Save matstani/4852df3eb4856bccbce4 to your computer and use it in GitHub Desktop.
componentフレームワークを利用したシステムの起動・停止・リロード関数
(ns user
(:require [com.stuartsierra.component :as component]
[clojure.tools.namespace.repl :refer (refresh)]
[example-component-ring.component :as app]))
(def system nil)
;; システム初期化
(defn init []
(alter-var-root #'system
(constantly (app/create-system {:port 3000}))))
;; システム起動
(defn start []
(alter-var-root #'system component/start))
;; システム停止
(defn stop []
(alter-var-root #'system
(fn [s] (when s (component/stop s)))))
;; 初期化&起動
(defn go []
(init)
(start))
;; システムリロード
(defn reset []
(stop)
(refresh :after 'user/go))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment