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

Merge pull request #1539 from metabase/fix_database_sync

Fix database sync
parents a6a3a709 a1fa87eb
No related branches found
No related tags found
No related merge requests found
......@@ -178,7 +178,8 @@
[id]
(let-404 [db (Database id)]
(write-check db)
(future (driver/sync-database! db))) ; run sync-tables asynchronously
;; just publish a message and let someone else deal with the logistics
(events/publish-event :database-trigger-sync db))
{:status :ok})
......
......@@ -47,8 +47,8 @@
(defn- mark-inactive-tables!
"Mark any `Tables` that are no longer active as such. These are ones that exist in the DB but didn't come back from `active-tables`."
[database active-tables existing-table->id]
(doseq [[[{table :name, schema :schema, :as table}] table-id] existing-table->id]
(when-not (contains? active-tables table)
(doseq [[{table :name, schema :schema, :as table} table-id] existing-table->id]
(when-not (contains? (set (map :name active-tables)) table)
(upd Table table-id :active false)
(log/info (u/format-color 'cyan "Marked table %s.%s%s as inactive." (:name database) (if schema (str schema \.) "") table))
......
......@@ -10,7 +10,8 @@
(def sync-database-topics
"The `Set` of event topics which are subscribed to for use in database syncing."
#{:database-create})
#{:database-create
:database-trigger-sync})
(def ^:private sync-database-channel
"Channel for receiving event notifications we want to subscribe to for database sync events."
......@@ -28,7 +29,10 @@
(when-let [{topic :topic object :item} sync-database-event]
(when-let [database (db/sel :one Database :id (events/object->model-id topic object))]
;; just kick off a sync on another thread
(future (driver/sync-database! database))))
(future (try
(driver/sync-database! database)
(catch Throwable t
(log/error (format "Error syncing Database: %d" (:id database)) t))))))
(catch Throwable e
(log/warn (format "Failed to process sync-database event. %s" (:topic sync-database-event)) e))))
......
......@@ -19,7 +19,7 @@
(jobs/defjob SyncDatabases
[ctx]
(dorun
(for [database (db/sel :many Database :is_sample false)] ; skip Sample Dataset DB
(for [database (db/sel :many Database :is_sample false)] ; skip Sample Dataset DB
(try
;; NOTE: this happens synchronously for now to avoid excessive load if there are lots of databases
(driver/sync-database! database)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment