diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-17 13:55:55 -0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-17 13:55:55 -0200 |
commit | 98056e815a6dcd36d7377d3cd823a4aaf5a3d9fa (patch) | |
tree | 61f453e1b21634e0f2d740ff61091d182e145184 /src/clj/queue_api/core.clj | |
download | queue-api-98056e815a6dcd36d7377d3cd823a4aaf5a3d9fa.tar.gz queue-api-98056e815a6dcd36d7377d3cd823a4aaf5a3d9fa.tar.bz2 queue-api-98056e815a6dcd36d7377d3cd823a4aaf5a3d9fa.zip |
Initial commit
Diffstat (limited to 'src/clj/queue_api/core.clj')
-rw-r--r-- | src/clj/queue_api/core.clj | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/clj/queue_api/core.clj b/src/clj/queue_api/core.clj new file mode 100644 index 0000000..1647375 --- /dev/null +++ b/src/clj/queue_api/core.clj @@ -0,0 +1,48 @@ +(ns queue-api.core + (:require [queue-api.handler :as handler] + [luminus.repl-server :as repl] + [luminus.http-server :as http] + [queue-api.config :refer [env]] + [clojure.tools.cli :refer [parse-opts]] + [clojure.tools.logging :as log] + [mount.core :as mount]) + (:gen-class)) + +(def cli-options + [["-p" "--port PORT" "Port number" + :parse-fn #(Integer/parseInt %)]]) + +(mount/defstate ^{:on-reload :noop} http-server + :start + (http/start + (-> env + (assoc :handler #'handler/app) + (update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime))))) + (update :port #(or (-> env :options :port) %)))) + :stop + (http/stop http-server)) + +(mount/defstate ^{:on-reload :noop} repl-server + :start + (when-let [nrepl-port (env :nrepl-port)] + (repl/start {:port nrepl-port})) + :stop + (when repl-server + (repl/stop repl-server))) + + +(defn stop-app [] + (doseq [component (:stopped (mount/stop))] + (log/info component "stopped")) + (shutdown-agents)) + +(defn start-app [args] + (doseq [component (-> args + (parse-opts cli-options) + mount/start-with-args + :started)] + (log/info component "started")) + (.addShutdownHook (Runtime/getRuntime) (Thread. stop-app))) + +(defn -main [& args] + (start-app args)) |