Record the failure of card operation when pulse is sent to the database

Record the card operation failure when the pulse is sent to the database, in the following code

(s/defn ^:private render-pulse-card-body :- common/RenderedPulseCard
  [render-type timezone-id :- (s/maybe s/Str) card {
    
    :keys [data error], :as results}]
  (log/info (.toString (.getClass card))  (.toString  card))
    (log/info (.toString (.getClass render-type))  (.toString  render-type))
 ;  (log/info (.toString (.getClass :as))  (.toString  :as))
  (log/info (str (:id card)) "---" (:name  card))
  (

  try
    (when error
      (throw (ex-info (tru "Card has errors: {0}" error) results)))
    (let [chart-type (or (detect-pulse-chart-type card data)
                         (when (is-attached? card)
                           :attached)
                         :unknown)]
      (log/info (trs "Rendering pulse card with chart-type {0} and render-type {1}" chart-type render-type))
      (body/render chart-type render-type timezone-id card data))
;;      (body/render :bar render-type timezone-id card data))
    (catch Throwable e
    		(db/insert! pulse_card_task_failure/CardFailure
          :fail_at   (java-time/instant (System/currentTimeMillis))
          :card_id   (:id card) 
          :fail_details (.getMessage e)
          )
      (log/error e (trs "Pulse card render error"))
      (body/render :error nil nil nil nil))))

Add the following code

	(db/insert! pulse_card_task_failure/CardFailure
          :fail_at   (java-time/instant (System/currentTimeMillis))
          :card_id   (:id card) 
          :fail_details (.getMessage e)
          )

Add the following files

(ns metabase.models.pulse_card_task_failure
  (:require [toucan
             [db :as db]
             [models :as models]]))
(models/defmodel CardFailure :pulse_card_task_failure)

Guess you like

Origin blog.csdn.net/weixin_40455124/article/details/110004780