Skip to content
Snippets Groups Projects
Unverified Commit 24c55f8a authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

Add more logs for sending notification (#50836) (#50849)


Co-authored-by: default avatarNgoc Khuat <qn.khuat@gmail.com>
parent e48212bc
No related branches found
No related tags found
No related merge requests found
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
(log/debugf "[Notification %d] Sent to channel %s with %d retries" (log/debugf "[Notification %d] Sent to channel %s with %d retries"
notification-id (handler->channel-name handler) (count @retry-errors)))) notification-id (handler->channel-name handler) (count @retry-errors))))
(catch Throwable e (catch Throwable e
(log/errorf e "[Notification %d] Error sending notification!" (:notification_id handler))))) (log/errorf e "[Notification %d] Error sending notification!" notification-id))))
(defn- noti-handlers (defn- noti-handlers
[notification-info] [notification-info]
...@@ -136,33 +136,33 @@ ...@@ -136,33 +136,33 @@
"Send the notification to all handlers synchronously. Do not use this directly, use *send-notification!* instead." "Send the notification to all handlers synchronously. Do not use this directly, use *send-notification!* instead."
[notification-info :- notification.payload/Notification] [notification-info :- notification.payload/Notification]
(try (try
(let [handlers (noti-handlers notification-info) (log/infof "[Notification %d] Sending" (:id notification-info))
notification-payload (notification.payload/notification-payload notification-info)] (let [handlers (noti-handlers notification-info)]
(if (notification.payload/should-send-notification? notification-payload) (task-history/with-task-history {:task "notification-send"
(do :task_details {:notification_id (:id notification-info)
(log/debugf "[Notification %d] Found %d handlers" (:id notification-info) (count handlers)) :notification_handlers (map #(select-keys % [:id :channel_type :channel_id :template_id]) handlers)}}
(task-history/with-task-history (let [notification-payload (notification.payload/notification-payload notification-info)]
{:task "notification-send" (if (notification.payload/should-send-notification? notification-payload)
:task_details {:notification_id (:id notification-info) (do
:notification_handlers (map #(select-keys % [:id :channel_type :channel_id :template_id]) handlers)}} (log/debugf "[Notification %d] Found %d handlers" (:id notification-info) (count handlers))
(doseq [handler handlers] (doseq [handler handlers]
(let [channel-type (:channel_type handler) (let [channel-type (:channel_type handler)
messages (channel/render-notification messages (channel/render-notification
channel-type channel-type
notification-payload notification-payload
(:template handler) (:template handler)
(:recipients handler))] (:recipients handler))]
(log/debugf "[Notification %d] Got %d messages for channel %s with template %d" (log/debugf "[Notification %d] Got %d messages for channel %s with template %d"
(:id notification-info) (count messages) (:id notification-info) (count messages)
(handler->channel-name handler) (handler->channel-name handler)
(-> handler :template :id)) (-> handler :template :id))
(doseq [message messages] (doseq [message messages]
(log/infof "[Notification %d] Sending message to channel %s" (log/infof "[Notification %d] Sending message to channel %s"
(:id notification-info) (:channel_type handler)) (:id notification-info) (:channel_type handler))
(channel-send-retrying! (:id notification-info) (:payload_type notification-info) handler message)))) (channel-send-retrying! (:id notification-info) (:payload_type notification-info) handler message))))
(do-after-notification-sent notification-info) (do-after-notification-sent notification-info)
(log/infof "[Notification %d] Sent successfully" (:id notification-info)))) (log/infof "[Notification %d] Sent successfully" (:id notification-info)))
(log/infof "[Notification %d] Skipping" (:id notification-info)))) (log/infof "[Notification %d] Skipping" (:id notification-info))))))
(catch Exception e (catch Exception e
(log/errorf e "[Notification %d] Failed to send" (:id notification-info)) (log/errorf e "[Notification %d] Failed to send" (:id notification-info))
(throw e))) (throw e)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment