Liking cljdoc? Tell your friends :D

salutem

Clojars Project Clojars Downloads GitHub Contributors

A system for defining and maintaining a collection of health checks.

salutem supports:

  • both realtime and background checks
  • a registry for storing, finding and resolving checks
  • an asynchronous maintenance system for ensuring that the results of checks are kept up-to-date; and
  • notifying via callbacks after checks are evaluated.

salutem also provides check function implementations for:

  • data sources; and
  • HTTP endpoints.

Install

Add the following to your project.clj file:

[io.logicblocks/salutem.core "0.1.8"]

Documentation

Usage

(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)

License

Copyright © 2023 LogicBlocks Maintainers

Distributed under the terms of the MIT License.

Can you improve this documentation? These fine people already did:
Toby Clemson, Circle CI & Jordan Robinson
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close