Print when there is a notification

This commit is contained in:
niten 2023-05-22 10:12:38 -07:00
parent e0d4400c5f
commit 87b8b005b3
1 changed files with 11 additions and 10 deletions

View File

@ -24,25 +24,26 @@
(<= 4 urgency 7) :normal (<= 4 urgency 7) :normal
(<= 8 urgency 10) :critical)) (<= 8 urgency 10) :critical))
(defn listen! [& {app :app mqtt-client (defn listen! [& {app :app
:mqtt-client topic mqtt-client :mqtt-client
:topic logger topic :topic
:logger urgency-threshold logger :logger
:urgency-threshold}] urgency-threshold :urgency-threshold}]
(let [note-chan (mqtt/subscribe! mqtt-client topic)] (let [note-chan (mqtt/subscribe! mqtt-client topic)]
(go-loop [note-msg (<! note-chan)] (go-loop [note-msg (<! note-chan)]
(if note-msg (if note-msg
(let [note (:payload note-msg)] (let [note (:payload note-msg)]
(if (t/validate Notification note) (if (t/validate Notification note)
(if (>= (:urgency note) urgency-threshold) (if (>= (:urgency note) urgency-threshold)
(notify/send-notification! mqtt-client (do (log/info! logger (format "notification: %s" (:summary note)))
(-> note (notify/send-notification! mqtt-client
(assoc :app app) (-> note
(update :urgency codify-urgency))) (assoc :app app)
(update :urgency codify-urgency))))
(log/info! logger (format "ignoring low-urgency message (%s < %s): %s" (log/info! logger (format "ignoring low-urgency message (%s < %s): %s"
(:urgency note) (:urgency note)
urgency-threshold urgency-threshold
note))) (:summary note))))
(let [err (humanize (t/explain Notification note))] (let [err (humanize (t/explain Notification note))]
(log/error! logger (format "rejecting invalid notification: %s (%s)\n%s" (log/error! logger (format "rejecting invalid notification: %s (%s)\n%s"
(:summary err) (:body err) (:summary err) (:body err)