/
validation.clj
39 lines (36 loc) · 1.17 KB
/
validation.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(ns circuit-breaker-fn.validation
(:require [clojure.spec.alpha :as s]
[circuit-breaker-fn.util :as ut]))
(s/def ::fail-limit pos-int?)
(s/def ::fail-window pos-int?)
(s/def ::success-limit pos-int?)
(s/def ::open-timeout pos-int?)
(s/def ::drop-fn fn?)
(s/def ::ex-fn fn?)
(s/def ::locking? boolean?)
(s/def ::try-locking? boolean?)
(s/def ::meta map?)
(s/def ::time-unit (set (keys ut/time-units)))
(s/def ::timeout-unit ::time-unit)
(s/def ::fail-window-unit ::time-unit)
(s/def ::success-block
(s/or :sleep-millis (complement neg?)
:block-fn fn?))
(s/def ::cb-opts
(s/keys :req-un [::fail-limit
::fail-window
::success-limit
::open-timeout
::drop-fn
::ex-fn]
:opt-un [::success-block
::locking?
::try-locking?
::timeout-unit
::fail-window-unit
::meta]))
(defn validate!
[opts]
(when-some [problems (s/explain-data ::cb-opts opts)]
(throw
(ex-info "Non-conforming parameters provided!" problems))))