mirror of https://github.com/status-im/timbre.git
Housekeeping
This commit is contained in:
parent
a29879d1f9
commit
de9d1b001e
|
@ -174,7 +174,7 @@
|
||||||
(let [timers (atom {})] ; {:hash last-appended-time-msecs ...}
|
(let [timers (atom {})] ; {:hash last-appended-time-msecs ...}
|
||||||
(fn [{ns :ns [x1 & _] :args :as apfn-args}]
|
(fn [{ns :ns [x1 & _] :args :as apfn-args}]
|
||||||
(let [now (System/currentTimeMillis)
|
(let [now (System/currentTimeMillis)
|
||||||
hash (str ns "/" x1)
|
hash (str ns "/" x1) ; TODO Alternatives?
|
||||||
limit? (fn [last-msecs]
|
limit? (fn [last-msecs]
|
||||||
(and last-msecs (<= (- now last-msecs)
|
(and last-msecs (<= (- now last-msecs)
|
||||||
limit-per-msecs)))]
|
limit-per-msecs)))]
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
(let [[subject & body] args]
|
(let [[subject & body] args]
|
||||||
(postal/send-message
|
(postal/send-message
|
||||||
(assoc postal-config
|
(assoc postal-config
|
||||||
|
;; TODO Better to just use trunc'd message as subject?
|
||||||
:subject (str prefix " - " (or subject throwable))
|
:subject (str prefix " - " (or subject throwable))
|
||||||
:body (str (str/join \space body)
|
:body (str (str/join \space body)
|
||||||
(timbre/stacktrace throwable "\n")))))))})
|
(timbre/stacktrace throwable "\n")))))))})
|
|
@ -13,13 +13,13 @@
|
||||||
(defn memoize-ttl
|
(defn memoize-ttl
|
||||||
"Like `memoize` but invalidates the cache for a set of arguments after TTL
|
"Like `memoize` but invalidates the cache for a set of arguments after TTL
|
||||||
msecs has elapsed."
|
msecs has elapsed."
|
||||||
[ttl f]
|
[ttl-ms f]
|
||||||
(let [cache (atom {})]
|
(let [cache (atom {})]
|
||||||
(fn [& args]
|
(fn [& args]
|
||||||
(let [{:keys [time-cached d-result]} (@cache args)
|
(let [{:keys [time-cached d-result]} (@cache args)
|
||||||
now (System/currentTimeMillis)]
|
now (System/currentTimeMillis)]
|
||||||
|
|
||||||
(if (and time-cached (< (- now time-cached) ttl))
|
(if (and time-cached (< (- now time-cached) ttl-ms))
|
||||||
@d-result
|
@d-result
|
||||||
(let [d-result (delay (apply f args))]
|
(let [d-result (delay (apply f args))]
|
||||||
(swap! cache assoc args {:time-cached now :d-result d-result})
|
(swap! cache assoc args {:time-cached now :d-result d-result})
|
||||||
|
|
Loading…
Reference in New Issue