Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
edafc10c
Commit
edafc10c
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
use the events system for triggering a database sync when a :database-create event is triggered.
parent
f13c45ab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/database.clj
+2
-4
2 additions, 4 deletions
src/metabase/api/database.clj
src/metabase/events/sync_database.clj
+45
-0
45 additions, 0 deletions
src/metabase/events/sync_database.clj
with
47 additions
and
4 deletions
src/metabase/api/database.clj
+
2
−
4
View file @
edafc10c
...
...
@@ -5,6 +5,7 @@
[
metabase.api.common
:refer
:all
]
[
metabase.db
:refer
:all
]
[
metabase.driver
:as
driver
]
[
metabase.events
:as
events
]
(
metabase.models
common
[
hydrate
:refer
[
hydrate
]]
[
database
:refer
[
Database
]]
...
...
@@ -31,10 +32,7 @@
;; TODO - we should validate the contents of `details` here based on the engine
(
check-superuser
)
(
let-500
[
new-db
(
ins
Database
:name
name
:engine
engine
:details
details
)]
;; kick off background job to gather schema metadata about our new db
(
future
(
driver/sync-database!
new-db
))
;; make sure we return the newly created db object
new-db
))
(
events/publish-event
:database-create
new-db
)))
(
defendpoint
GET
"/form_input"
"Values of options for the create/edit `Database` UI."
...
...
This diff is collapsed.
Click to expand it.
src/metabase/events/sync_database.clj
0 → 100644
+
45
−
0
View file @
edafc10c
(
ns
metabase.events.sync-database
(
:require
[
clojure.core.async
:as
async
]
[
clojure.tools.logging
:as
log
]
[
metabase.config
:as
config
]
[
metabase.db
:as
db
]
[
metabase.driver
:as
driver
]
[
metabase.events
:as
events
]
[
metabase.models.database
:refer
[
Database
]]))
(
def
sync-database-topics
"The `Set` of event topics which are subscribed to for use in database syncing."
#
{
:database-create
})
(
def
^
:private
sync-database-channel
"Channel for receiving event notifications we want to subscribe to for database sync events."
(
async/chan
))
;;; ## ---------------------------------------- EVENT PROCESSING ----------------------------------------
(
defn
process-sync-database-event
"Handle processing for a single event notification received on the revisions-channel"
[
sync-database-event
]
;; try/catch here to prevent individual topic processing exceptions from bubbling up. better to handle them here.
(
try
(
log/info
"holla"
)
(
when-let
[{
topic
:topic
object
:item
}
sync-database-event
]
(
when-let
[
database
(
db/sel
:one
Database
:id
(
events/object->model-id
topic
object
))]
(
log/info
"kicking off"
database
)
;; just kick off a sync on another thread
(
future
(
driver/sync-database!
database
))))
(
catch
Throwable
e
(
log/warn
(
format
"Failed to process sync-database event. %s"
(
:topic
sync-database-event
))
e
))))
;;; ## ---------------------------------------- LIFECYLE ----------------------------------------
;; this is what actually kicks off our listener for events
(
when
(
config/is-prod?
)
(
log/info
"Starting database sync events listener"
)
(
events/start-event-listener
sync-database-topics
sync-database-channel
process-sync-database-event
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment