From 97f2f7018ddcdaee02560e1feba3008b3636fd58 Mon Sep 17 00:00:00 2001 From: Joshua Heimbach Date: Tue, 16 Jan 2018 12:23:18 +0000 Subject: [PATCH] Move bluegenes.server to bluegenes.core --- Procfile | 2 +- project.clj | 2 +- src/clj/bluegenes/core.clj | 35 ++++++++++++++++++++++++++++++++++- src/clj/bluegenes/server.clj | 34 ---------------------------------- 4 files changed, 36 insertions(+), 37 deletions(-) delete mode 100644 src/clj/bluegenes/server.clj diff --git a/Procfile b/Procfile index a2e79cb46..dba79fb8a 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: java -cp target/bluegenes.jar clojure.main -m bluegenes.server \ No newline at end of file +web: java -cp target/bluegenes.jar clojure.main -m bluegenes.core \ No newline at end of file diff --git a/project.clj b/project.clj index 94886c3a2..dfcefa4bb 100644 --- a/project.clj +++ b/project.clj @@ -152,7 +152,7 @@ :optimizations :none}}}} - :main bluegenes.server + :main bluegenes.core :uberjar-name "bluegenes.jar" diff --git a/src/clj/bluegenes/core.clj b/src/clj/bluegenes/core.clj index b2c62aca7..ce923b688 100644 --- a/src/clj/bluegenes/core.clj +++ b/src/clj/bluegenes/core.clj @@ -1 +1,34 @@ -(ns bluegenes.core) +(ns bluegenes.core + (:require [bluegenes.handler :refer [handler]] + [config.core :refer [env]] + [ring.adapter.jetty :refer [run-jetty]] + [taoensso.timbre :as timbre :refer [infof errorf]] + [mount.core :as mount] + ; Including this namespace establishes the database connection when (mount/start) is called: + [bluegenes.mounts :as mounts] + [bluegenes.migrations :as migrations]) + (:gen-class)) + +(defn ->int + "Force a value to a number (environment variables are read as strings)" + [n] + (cond + (string? n) (read-string n) + (int? n) n + :else n)) + +(defn -main + "Start the BlueGenes server. This is the main entry point for the application" + [& args] + ; Parse the port from the configuration file, environment variables, or default to 5000 + ; "PORT" is often the default value for app serving platforms such as Heroku and Dokku + (let [port (->int (or (:server-port env) (:port env) 5000))] + (timbre/set-level! :info) ; Enable Logging + (try + (do + (mount/start) ; Mount our database connection + (migrations/migrate)) ; Apply any database migrations that haven't been applied + (catch Exception e (errorf "Unable to connect to database: %s" (.getMessage e)))) + ; Start the Jetty server by passing in the URL routes defined in 'handler' + (run-jetty handler {:port port :join? false}) + (infof "Bluegenes server started on port: %s" port))) diff --git a/src/clj/bluegenes/server.clj b/src/clj/bluegenes/server.clj deleted file mode 100644 index 9a080854b..000000000 --- a/src/clj/bluegenes/server.clj +++ /dev/null @@ -1,34 +0,0 @@ -(ns bluegenes.server - (:require [bluegenes.handler :refer [handler]] - [config.core :refer [env]] - [ring.adapter.jetty :refer [run-jetty]] - [taoensso.timbre :as timbre :refer [infof errorf]] - [mount.core :as mount] - ; Including this namespace establishes the database connection when (mount/start) is called: - [bluegenes.mounts :as mounts] - [bluegenes.migrations :as migrations]) - (:gen-class)) - -(defn ->int - "Force a value to a number (environment variables are read as strings)" - [n] - (cond - (string? n) (read-string n) - (int? n) n - :else n)) - -(defn -main - "Start the BlueGenes server. This is the main entry point for the application" - [& args] - ; Parse the port from the configuration file, environment variables, or default to 5000 - ; "PORT" is often the default value for app serving platforms such as Heroku and Dokku - (let [port (->int (or (:server-port env) (:port env) 5000))] - (timbre/set-level! :info) ; Enable Logging - (try - (do - (mount/start) ; Mount our database connection - (migrations/migrate)) ; Apply any database migrations that haven't been applied - (catch Exception e (errorf "Unable to connect to database: %s" (.getMessage e)))) - ; Start the Jetty server by passing in the URL routes defined in 'handler' - (run-jetty handler {:port port :join? false}) - (infof "Bluegenes server started on port: %s" port)))