A system for defining and maintaining a collection of health checks.
salutem
supports:
Add the following to your project.clj
file:
[io.logicblocks/salutem.core "0.1.6"]
(require '[salutem.core :as salutem])
(defn database-health-check-fn
[context callback-fn]
(callback-fn
(salutem/unhealthy
{:error :connection-failed})))
(defn external-service-health-check-fn
[context callback-fn]
(callback-fn
(salutem/healthy
{:latency-ms 200})))
(def registry-atom
(atom
(-> (salutem/empty-registry)
(salutem/with-check
(salutem/realtime-check :database
database-health-check-fn
{:salutem/timeout (salutem/duration 5 :seconds)}))
(salutem/with-check
(salutem/background-check :external-service
external-service-health-check-fn
{:salutem/time-to-re-evaluation (salutem/duration 30 :seconds)})))))
(def maintainer
(salutem/maintain registry-atom))
(salutem/resolve-checks @registry-atom)
; => {:database
; {:error :connection-failed
; :salutem/status :unhealthy
; :salutem/evaluated-at #time/instant"2021-08-18T23:39:29.234Z"}
; :external-service
; {:latency-ms 200,
; :salutem/status :healthy,
; :salutem/evaluated-at #time/instant"2021-08-18T23:39:10.383Z"}}
; ...5 seconds later...
(salutem/resolve-checks @registry-atom)
; => {:database
; {:error :connection-failed
; :salutem/status :unhealthy
; :salutem/evaluated-at #time/instant"2021-08-18T23:39:34.234Z"}
; :external-service
; {:latency-ms 200,
; :salutem/status :healthy,
; :salutem/evaluated-at #time/instant"2021-08-18T23:39:10.383Z"}}
(salutem/shutdown maintainer)
Copyright © 2021 LogicBlocks Maintainers
Distributed under the terms of the MIT License.
Can you improve this documentation? These fine people already did:
Toby Clemson & Jordan RobinsonEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close