Skip to content
Snippets Groups Projects
Commit 538dc12f authored by Cam Saül's avatar Cam Saül Committed by GitHub
Browse files

Merge pull request #3675 from metabase/minor-cleanup

Rename publish-event -> publish-event! :shower:
parents 5f08356b d021fe3b
No related branches found
No related tags found
No related merge requests found
Showing with 43 additions and 42 deletions
......@@ -173,7 +173,7 @@
:display display
:name name
:visualization_settings visualization_settings)
(events/publish-event :card-create)))
(events/publish-event! :card-create)))
(defendpoint GET "/:id"
......@@ -182,7 +182,7 @@
(-> (read-check Card id)
(hydrate :creator :dashboard_count :labels)
(assoc :actor_id *current-user-id*)
(->> (events/publish-event :card-read))
(->> (events/publish-event! :card-read))
(dissoc :actor_id)))
......@@ -210,7 +210,7 @@
(not archived)
(:archived card)) :card-unarchive
:else :card-update)]
(events/publish-event event (assoc (Card id) :actor_id *current-user-id*)))))
(events/publish-event! event (assoc (Card id) :actor_id *current-user-id*)))))
(defendpoint DELETE "/:id"
......@@ -218,7 +218,7 @@
[id]
(let [card (write-check Card id)]
(u/prog1 (db/cascade-delete! Card :id id)
(events/publish-event :card-delete (assoc card :actor_id *current-user-id*)))))
(events/publish-event! :card-delete (assoc card :actor_id *current-user-id*)))))
;;; ------------------------------------------------------------ Favoriting ------------------------------------------------------------
......
......@@ -61,7 +61,7 @@
(hydrate :creator [:ordered_cards [:card :creator] :series])
read-check
hide-unreadable-cards)
(events/publish-event :dashboard-read (assoc <> :actor_id *current-user-id*))))
(events/publish-event! :dashboard-read (assoc <> :actor_id *current-user-id*))))
(defendpoint PUT "/:id"
......@@ -79,7 +79,7 @@
[id]
(let [dashboard (write-check Dashboard id)]
(u/prog1 (db/cascade-delete! Dashboard :id id)
(events/publish-event :dashboard-delete (assoc dashboard :actor_id *current-user-id*)))))
(events/publish-event! :dashboard-delete (assoc dashboard :actor_id *current-user-id*)))))
(defendpoint POST "/:id/cards"
......@@ -96,9 +96,8 @@
:series (or series [])}
dashboard-card (-> (merge dashboard-card defaults)
(update :series #(filter identity (map :id %))))]
(let-500 [result (create-dashboard-card! dashboard-card)]
(events/publish-event :dashboard-add-cards {:id id :actor_id *current-user-id* :dashcards [result]})
result)))
(u/prog1 (check-500 (create-dashboard-card! dashboard-card))
(events/publish-event! :dashboard-add-cards {:id id, :actor_id *current-user-id*, :dashcards [<>]}))))
(defendpoint PUT "/:id/cards"
......@@ -118,7 +117,7 @@
;; ensure the dashcard we are updating is part of the given dashboard
(when (contains? dashcard-ids dashcard-id)
(update-dashboard-card! (update dashboard-card :series #(filter identity (map :id %)))))))
(events/publish-event :dashboard-reposition-cards {:id id :actor_id *current-user-id* :dashcards cards})
(events/publish-event! :dashboard-reposition-cards {:id id, :actor_id *current-user-id*, :dashcards cards})
{:status :ok})
......
......@@ -216,7 +216,7 @@
(if-not (false? (:valid details-or-error))
;; no error, proceed with creation
(let-500 [new-db (db/insert! Database, :name name, :engine engine, :details details-or-error, :is_full_sync is_full_sync)]
(events/publish-event :database-create new-db)
(events/publish-event! :database-create new-db)
new-db)
;; failed to connect, return error
{:status 400
......@@ -261,7 +261,7 @@
:description description
:caveats caveats
:points_of_interest points_of_interest)) ; TODO - this means one cannot unset the description. Does that matter?
(events/publish-event :database-update (Database id)))
(events/publish-event! :database-update (Database id)))
;; failed to connect, return error
{:status 400
:body conn-error}))))
......@@ -274,7 +274,7 @@
(let-404 [db (Database id)]
(write-check db)
(u/prog1 (db/cascade-delete! Database :id id)
(events/publish-event :database-delete db))))
(events/publish-event! :database-delete db))))
;;; ------------------------------------------------------------ POST /api/database/:id/sync ------------------------------------------------------------
......@@ -284,7 +284,7 @@
"Update the metadata for this `Database`."
[id]
;; just publish a message and let someone else deal with the logistics
(events/publish-event :database-trigger-sync (write-check Database id))
(events/publish-event! :database-trigger-sync (write-check Database id))
{:status :ok})
......
......@@ -72,7 +72,7 @@
[id]
(let-404 [pulse (Pulse id)]
(u/prog1 (db/cascade-delete! Pulse :id id)
(events/publish-event :pulse-delete (assoc pulse :actor_id *current-user-id*)))))
(events/publish-event! :pulse-delete (assoc pulse :actor_id *current-user-id*)))))
(defendpoint GET "/form_input"
......
......@@ -29,7 +29,7 @@
(db/insert! Session
:id <>
:user_id (:id user))
(events/publish-event :user-login {:user_id (:id user), :session_id <>, :first_login (not (boolean (:last_login user)))})))
(events/publish-event! :user-login {:user_id (:id user), :session_id <>, :first_login (not (boolean (:last_login user)))})))
;;; ## API Endpoints
......
......@@ -61,7 +61,7 @@
:is_full_sync (if-not (nil? is_full_sync)
is_full_sync
true))
(events/publish-event :database-create)))
(events/publish-event! :database-create)))
;; clear the setup token now, it's no longer needed
(setup/clear-token!)
;; then we create a session right away because we want our new user logged in to continue the setup process
......@@ -69,8 +69,8 @@
:id session-id
:user_id (:id new-user))
;; notify that we've got a new user in the system AND that this user logged in
(events/publish-event :user-create {:user_id (:id new-user)})
(events/publish-event :user-login {:user_id (:id new-user), :session_id session-id, :first_login true})
(events/publish-event! :user-create {:user_id (:id new-user)})
(events/publish-event! :user-login {:user_id (:id new-user), :session_id session-id, :first_login true})
{:id session-id}))
......
......@@ -129,7 +129,7 @@
;; create setup token
(-init-create-setup-token)
;; publish install event
(events/publish-event :install {}))
(events/publish-event! :install {}))
(reset! metabase-initialization-progress 0.9)
;; deal with our sample dataset as needed
......
......@@ -53,8 +53,7 @@
Expects a map as input and the map must have a `:topic` key."
(async/pub events-channel :topic))
;; TODO - this should be named `publish-event!`
(defn publish-event
(defn publish-event!
"Publish an item into the events stream.
Returns the published item to allow for chaining."
[topic event-item]
......@@ -66,6 +65,7 @@
;;; ## ---------------------------------------- SUBSCRIPTION ----------------------------------------
;; TODO - rename to `subscribe-to-topic!`
(defn subscribe-to-topic
"Subscribe to a given topic of the general events stream.
Expects a topic to subscribe to and a `core.async` channel.
......@@ -75,6 +75,7 @@
(async/sub events-publication (keyword topic) channel)
channel)
;; TODO - rename to `subscribe-to-topics!`
(defn subscribe-to-topics
"Convenience method for subscribing to a series of topics against a single channel."
[topics channel]
......@@ -82,6 +83,7 @@
(doseq [topic topics]
(subscribe-to-topic topic channel)))
;; TODO - rename to `start-event-listener!`
(defn start-event-listener
"Initialize an event listener which runs on a background thread via `go-loop`."
[topics channel handler-fn]
......
......@@ -75,7 +75,7 @@
:description description
:parameters (or parameters [])
:creator_id user-id)
(events/publish-event :dashboard-create)))
(events/publish-event! :dashboard-create)))
(defn update-dashboard!
"Update a `Dashboard`"
......@@ -92,7 +92,7 @@
:points_of_interest points_of_interest
:show_in_getting_started show_in_getting_started)
(u/prog1 (Dashboard id)
(events/publish-event :dashboard-update (assoc <> :actor_id user-id))))
(events/publish-event! :dashboard-update (assoc <> :actor_id user-id))))
;;; ## ---------------------------------------- REVISIONS ----------------------------------------
......
......@@ -114,7 +114,7 @@
(update-dashboard-card-series! dashboard-card series))
;; fetch the fully updated dashboard card then return it (and fire off an event)
(->> (retrieve-dashboard-card id)
(events/publish-event :dashboard-card-update)))))
(events/publish-event! :dashboard-card-update)))))
(defn create-dashboard-card!
"Create a new `DashboardCard` by inserting it into the database along with all associated pieces of data such as `DashboardCardSeries`.
......@@ -142,7 +142,7 @@
;; return the full DashboardCard (and record our create event)
(-> (retrieve-dashboard-card id)
(assoc :actor_id creator_id)
(->> (events/publish-event :dashboard-card-create))
(->> (events/publish-event! :dashboard-card-create))
(dissoc :actor_id))))))
(defn delete-dashboard-card!
......@@ -152,4 +152,4 @@
(integer? user-id)]}
(let [{:keys [id]} (dashboard dashboard-card)]
(db/cascade-delete! DashboardCard :id (:id dashboard-card))
(events/publish-event :dashboard-remove-cards {:id id :actor_id user-id :dashcards [dashboard-card]})))
(events/publish-event! :dashboard-remove-cards {:id id :actor_id user-id :dashcards [dashboard-card]})))
......@@ -91,7 +91,7 @@
:description description
:is_active true
:definition definition)]
(-> (events/publish-event :metric-create metric)
(-> (events/publish-event! :metric-create metric)
(hydrate :creator))))
(defn exists?
......@@ -139,7 +139,7 @@
:show_in_getting_started show_in_getting_started
:definition definition)
(u/prog1 (retrieve-metric id)
(events/publish-event :metric-update (assoc <> :actor_id user-id, :revision_message revision_message))))
(events/publish-event! :metric-update (assoc <> :actor_id user-id, :revision_message revision_message))))
(defn delete-metric!
"Delete a `Metric`.
......@@ -156,4 +156,4 @@
(db/update! Metric id, :is_active false)
;; retrieve the updated metric (now retired)
(u/prog1 (retrieve-metric id)
(events/publish-event :metric-delete (assoc <> :actor_id user-id, :revision_message revision-message))))
(events/publish-event! :metric-delete (assoc <> :actor_id user-id, :revision_message revision-message))))
......@@ -181,7 +181,7 @@
;; add channels to the Pulse
(update-pulse-channels! pulse channels)
;; return the full Pulse (and record our create event)
(events/publish-event :pulse-create (retrieve-pulse id)))))
(events/publish-event! :pulse-create (retrieve-pulse id)))))
(defn update-pulse!
......@@ -206,4 +206,4 @@
(update-pulse-channels! pulse channels)
;; fetch the fully updated pulse and return it (and fire off an event)
(->> (retrieve-pulse id)
(events/publish-event :pulse-update))))
(events/publish-event! :pulse-update))))
......@@ -73,7 +73,7 @@
:description description
:is_active true
:definition definition)]
(-> (events/publish-event :segment-create segment)
(-> (events/publish-event! :segment-create segment)
(hydrate :creator))))
(defn exists?
......@@ -123,7 +123,7 @@
(when (not (nil? show_in_getting_started))
{:show_in_getting_started show_in_getting_started})))
(u/prog1 (retrieve-segment id)
(events/publish-event :segment-update (assoc <> :actor_id user-id, :revision_message revision_message))))
(events/publish-event! :segment-update (assoc <> :actor_id user-id, :revision_message revision_message))))
(defn delete-segment!
"Delete a `Segment`.
......@@ -140,4 +140,4 @@
(db/update! Segment id, :is_active false)
;; retrieve the updated segment (now retired)
(u/prog1 (retrieve-segment id)
(events/publish-event :segment-delete (assoc <> :actor_id user-id, :revision_message revision-message))))
(events/publish-event! :segment-delete (assoc <> :actor_id user-id, :revision_message revision-message))))
......@@ -332,7 +332,7 @@
;; this only works if the setting is updated via this specific function. Instead, we should define a custom setter for the relevant setting that additionally
;; performs the desired operations when the value is updated. This pattern is easier to understand, works no matter how the setting is changed, and doesn't run when
;; irrelevant changes (to other settings) are made.
(events/publish-event :settings-update settings))
(events/publish-event! :settings-update settings))
(defn- user-facing-info [setting]
......
......@@ -69,7 +69,7 @@
(let [start-time (System/nanoTime)
tracking-hash (str (java.util.UUID/randomUUID))]
(log/info (u/format-color 'magenta "Syncing %s database '%s'..." (name driver) (:name database)))
(events/publish-event :database-sync-begin {:database_id (:id database) :custom_id tracking-hash})
(events/publish-event! :database-sync-begin {:database_id (:id database) :custom_id tracking-hash})
(binding [qp/*disable-qp-logging* true
db/*disable-db-logging* true]
......@@ -85,7 +85,7 @@
(when full-sync?
(analyze/analyze-data-shape-for-tables! driver database)))
(events/publish-event :database-sync-end {:database_id (:id database)
(events/publish-event! :database-sync-end {:database_id (:id database)
:custom_id tracking-hash
:running_time (int (/ (- (System/nanoTime) start-time) 1000000.0))}) ; convert to ms
(log/info (u/format-color 'magenta "Finished syncing %s database '%s'. (%s)" (name driver) (:name database)
......@@ -111,6 +111,6 @@
(when full-sync?
(analyze/analyze-table-data-shape! driver table)))
(events/publish-event :table-sync {:table_id (:id table)})
(events/publish-event! :table-sync {:table_id (:id table)})
(log/info (u/format-color 'magenta "Finished syncing table '%s' from %s database '%s'. (%s)" (:display_name table) (name driver) (:name database)
(u/format-nanoseconds (- (System/nanoTime) start-time))))))
......@@ -3,9 +3,9 @@
[expectations :refer :all]
[metabase.events :as events]))
(def testing-topic :event-test-topic)
(def ^:private testing-topic :event-test-topic)
(def testing-sub-channel (async/chan))
(def ^:private testing-sub-channel (async/chan))
;; ## Basic Pub/Sub TESTS
......@@ -15,7 +15,7 @@
;; we should get back our originally posted object no matter what happens
(expect
{:some :object}
(events/publish-event testing-topic {:some :object}))
(events/publish-event! testing-topic {:some :object}))
;; when we receive a message it should be wrapped with {:topic `topic` :item `message body`}
(expect
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment