Skip to content
Snippets Groups Projects
Commit f57ca7b4 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

publish a `:database-update` event and create an event listener which calls...

publish a `:database-update` event and create an event listener which calls our driver notify-database-updated method whenever we get a :database-update event.
parent 40528602
Branches
Tags
No related merge requests found
......@@ -127,7 +127,8 @@
:engine engine
:details details
:is_full_sync is_full_sync))
(Database id))
(->> (Database id)
(events/publish-event :database-update)))
;; failed to connect, return error
{:status 400
:body conn-error}))))
......
(ns metabase.events.driver-notifications
(:require [clojure.core.async :as async]
[clojure.tools.logging :as log]
[metabase.db :as db]
[metabase.driver :as driver]
[metabase.events :as events]
[metabase.models.database :refer [Database]]))
(def ^:const driver-notifications-topics
"The `Set` of event topics which are subscribed to for use in driver notifications."
#{:database-update})
(def ^:private driver-notifications-channel
"Channel for receiving event notifications we want to subscribe to for driver notifications events."
(async/chan))
;;; ## ---------------------------------------- EVENT PROCESSING ----------------------------------------
(defn process-driver-notifications-event
"Handle processing for a single event notification received on the driver-notifications-channel"
[driver-notifications-event]
;; try/catch here to prevent individual topic processing exceptions from bubbling up. better to handle them here.
(try
(when-let [{topic :topic database :item} driver-notifications-event]
;; notify the appropriate driver about the updated database
(driver/notify-database-updated (driver/engine->driver (:engine database)) database))
(catch Throwable e
(log/warn (format "Failed to process driver notifications event. %s" (:topic driver-notifications-event)) e))))
;;; ## ---------------------------------------- LIFECYLE ----------------------------------------
(defn events-init
"Automatically called during startup; start event listener for database sync events."
[]
(events/start-event-listener driver-notifications-topics driver-notifications-channel process-driver-notifications-event))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment