mirror of https://github.com/status-im/timbre.git
Use ns as part of flood control message disambiguator
This commit is contained in:
parent
de5ab76955
commit
6c359427d9
|
@ -140,19 +140,20 @@
|
||||||
((fn [apfn]
|
((fn [apfn]
|
||||||
(if-not max-message-per-msecs
|
(if-not max-message-per-msecs
|
||||||
apfn
|
apfn
|
||||||
(let [;; {:msg last-appended-time-msecs ...}
|
(let [;; {:hash last-appended-time-msecs ...}
|
||||||
flood-timers (atom {})]
|
flood-timers (atom {})]
|
||||||
|
|
||||||
(fn [{:keys [message] :as apfn-args}]
|
(fn [{:keys [ns message] :as apfn-args}]
|
||||||
(let [now (System/currentTimeMillis)
|
(let [now (System/currentTimeMillis)
|
||||||
|
hash (str ns "/" message)
|
||||||
allow? (fn [last-msecs]
|
allow? (fn [last-msecs]
|
||||||
(if last-msecs
|
(if last-msecs
|
||||||
(> (- now last-msecs) max-message-per-msecs)
|
(> (- now last-msecs) max-message-per-msecs)
|
||||||
true))]
|
true))]
|
||||||
|
|
||||||
(when (allow? (@flood-timers message))
|
(when (allow? (@flood-timers hash))
|
||||||
(apfn apfn-args)
|
(apfn apfn-args)
|
||||||
(swap! flood-timers assoc message now))
|
(swap! flood-timers assoc hash now))
|
||||||
|
|
||||||
;; Occassionally garbage-collect all expired timers. Note
|
;; Occassionally garbage-collect all expired timers. Note
|
||||||
;; that due to snapshotting, garbage-collection can cause
|
;; that due to snapshotting, garbage-collection can cause
|
||||||
|
|
Loading…
Reference in New Issue