Skip to content

Commit

Permalink
Merge pull request #83 from miyamoen/add-healthcheck-api
Browse files Browse the repository at this point in the history
Add healthcheck api
  • Loading branch information
223kazuki authored Apr 27, 2017
2 parents 51fc49c + 01063e9 commit 6fa322f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/clj/job_streamer/control_bus/endpoint/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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))
Expand Down Expand Up @@ -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]]})))
Expand Down
5 changes: 2 additions & 3 deletions src/clj/job_streamer/control_bus/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 6fa322f

Please sign in to comment.