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
f4c5ed13
Commit
f4c5ed13
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
basic pub/sub framework using core.async
parent
4aad54ca
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/activity.clj
+65
-0
65 additions, 0 deletions
src/metabase/activity.clj
src/metabase/api/card.clj
+19
-16
19 additions, 16 deletions
src/metabase/api/card.clj
with
84 additions
and
16 deletions
src/metabase/activity.clj
0 → 100644
+
65
−
0
View file @
f4c5ed13
(
ns
metabase.activity
(
:require
[
clojure.core.async
:as
async
]))
;;; ## ---------------------------------------- PUBLICATION ----------------------------------------
(
def
^
:private
activity-channel
"Channel to host activity publications."
(
async/chan
))
(
def
^
:private
activity-publication
"Publication for general activity.
Expects a map as input and the map must have a `:topic` key."
(
async/pub
activity-channel
#
(
:topic
%
)))
(
defn
publish-activity
"Publish an item into the activity stream. Returns the published item."
[
topic
activity-item
]
{
:pre
[(
keyword
topic
)]}
(
async/go
(
async/>!
activity-channel
{
:topic
(
keyword
topic
)
:item
activity-item
}))
activity-item
)
;;; ## ---------------------------------------- SUBSCRIPTION ----------------------------------------
(
defn
subscribe-to-activity
"Subscribe to a given topic of the general activity stream.
Expects a topic to subscribe to and a `core.async` channel."
[
topic
channel
]
{
:pre
[(
keyword
topic
)]}
(
async/sub
activity-publication
(
keyword
topic
)
channel
))
;;; ## ---------------------------------------- ACTIVITY FEED ----------------------------------------
(
def
activity-feed-topics
"The `Set` of topics which are subscribed to and included in the Metabase published activity feed."
#
{
:card-create
:card-update
:dashboard-create
:dashboard-update
:dashboard-add-cards
:dashboard-remove-cards
:dashboard-reposition-cards
})
(
def
^
:private
activity-feed
"channel for activity feed subscription."
(
async/chan
))
;; create the core.async subscription for each of our activity-feed-topics
(
loop
[[
topic
&
rest
]
(
vec
activity-feed-topics
)]
(
subscribe-to-activity
topic
activity-feed
)
(
when
rest
(
recur
rest
)))
;; this is a placeholder for now
(
defn
take-and-print
[
channel
prefix
]
(
async/go-loop
[]
(
let
[
activity-item
(
async/<!
channel
)]
(
println
"Activity:"
(
:topic
activity-item
))
(
clojure.pprint/pprint
(
:item
activity-item
))
(
recur
))))
(
take-and-print
activity-feed
"activity-feed"
)
This diff is collapsed.
Click to expand it.
src/metabase/api/card.clj
+
19
−
16
View file @
f4c5ed13
...
...
@@ -2,6 +2,7 @@
(
:require
[
compojure.core
:refer
[
GET
POST
DELETE
PUT
]]
[
korma.core
:as
k
]
[
medley.core
:refer
[
mapply
]]
[
metabase.activity
:as
activity
]
[
metabase.api.common
:refer
:all
]
[
metabase.db
:refer
:all
]
(
metabase.models
[
hydrate
:refer
[
hydrate
]]
...
...
@@ -63,15 +64,15 @@
{
name
[
Required
NonEmptyString
]
public_perms
[
Required
PublicPerms
]
display
[
Required
CardDisplayType
]}
;; TODO - which other param
s ar
e required?
(
ins
Card
:creator_id
*current-user-id*
:dataset_query
dataset_query
:description
d
escription
:display
display
:name
name
:public_perms
public_perms
:visualization_settings
visualization_settings
))
(
->>
(
in
s
C
ar
d
:creator_id
*current-user-id*
:dataset_query
dataset_query
:description
description
:display
d
isplay
:name
name
:public_perms
public_perms
:visualization_settings
visualization_settings
)
(
activity/publish-activity
:card-create
)
))
(
defendpoint
GET
"/:id"
"Get `Card` with ID."
...
...
@@ -87,13 +88,15 @@
public_perms
PublicPerms
display
CardDisplayType
}
(
write-check
Card
id
)
(
check-500
(
upd-non-nil-keys
Card
id
:dataset_query
dataset_query
:description
description
:display
display
:name
name
:public_perms
public_perms
:visualization_settings
visualization_settings
))
(
->>
(
upd-non-nil-keys
Card
id
:dataset_query
dataset_query
:description
description
:display
display
:name
name
:public_perms
public_perms
:visualization_settings
visualization_settings
)
(
activity/publish-activity
:card-update
))
;; TODO - have revision stuff work using activity framework and then we can remove this call
(
push-revision
:entity
Card,
:object
(
Card
id
)))
(
defendpoint
DELETE
"/:id"
...
...
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