diff --git a/src/clj/job_streamer/control_bus/endpoint/api.clj b/src/clj/job_streamer/control_bus/endpoint/api.clj index e8e69df..c1b05e2 100644 --- a/src/clj/job_streamer/control_bus/endpoint/api.clj +++ b/src/clj/job_streamer/control_bus/endpoint/api.clj @@ -6,6 +6,7 @@ [compojure.core :refer [ANY GET POST routes]] [bouncer.validators :as v] [ring.util.response :refer [content-type]] + [datomic.api :as d] (job-streamer.control-bus.component [apps :as apps] [jobs :as jobs] @@ -19,7 +20,7 @@ [validation :refer [validate]] [util :refer [parse-body]]))) -(defn api-endpoint [{:keys [jobs agents calendar scheduler apps auth]}] +(defn api-endpoint [{:keys [jobs agents calendar scheduler apps auth datomic]}] (routes ;; Auth (ANY "/auth" request (auth/auth-resource auth)) @@ -97,6 +98,12 @@ (apps/stats-resource apps app-name)) (GET "/version" [] (-> {:body (clojure.string/replace (str "\"" (slurp "VERSION") "\"") "\n" "")} (content-type "text/plain"))) + ;; Health Check + (GET "/healthcheck" [] + (try + (d/connect (:uri datomic)) + {:status 200} + (catch Exception e {:status 503}))) ;; For debug ;(GET "/logs" [] (pr-str (model/query '{:find [[(pull ?log [*]) ...]] :where [[?log :execution-log/level]]}))) diff --git a/src/clj/job_streamer/control_bus/system.clj b/src/clj/job_streamer/control_bus/system.clj index 13947c6..0000a49 100644 --- a/src/clj/job_streamer/control_bus/system.clj +++ b/src/clj/job_streamer/control_bus/system.clj @@ -24,7 +24,6 @@ [auth :refer [auth-component]]) (job-streamer.control-bus.endpoint [api :refer [api-endpoint]]) - [job-streamer.control-bus.endpoint.api :refer [api-endpoint]] [clojure.tools.logging :as log] [buddy.auth :refer [authenticated?]] [buddy.auth.backends.session :refer [session-backend]] @@ -58,7 +57,7 @@ (header "Access-Control-Allow-Origin" access-control-allow-origin) (header "Access-Control-Allow-Credentials" "true")))))) -(def access-rules [{:pattern #"^/(?!auth|user).*$" +(def access-rules [{:pattern #"^/(?!auth|user|healthcheck|version).*$" :handler authenticated?}]) (defn token-base [token-provider] @@ -116,7 +115,7 @@ (component/system-using {:http [:app :socketapp] :app [:api :token] - :api [:apps :calendar :agents :jobs :scheduler :auth] + :api [:apps :calendar :agents :jobs :scheduler :auth :datomic] :socketapp [:datomic :jobs :agents] :jobs [:datomic :scheduler :agents :apps] :agents [:datomic]