Liking cljdoc? Tell your friends :D

metabase.models.pulse

Notifcations are ways to deliver the results of Questions to users without going through the normal Metabase UI. At the time of this writing, there are two delivery mechanisms for Notifications -- email and Slack notifications; these destinations are known as 'Channels'. Notifications themselves are futher divied into two categories -- 'Pulses', which are sent at specified intervals, and 'Alerts', which are sent when certain conditions are met (such as a query returning results).

Because 'Pulses' were originally the only type of Notification, this name is still used for the model itself, and in some of the functions below. To keep things clear try to make sure you use the term 'Notification' for things that work with either type.

One more thing to keep in mind: this code is pretty old and doesn't follow the code patterns used in the other Metabase models. There is a plethora of CRUD functions for working with Pulses that IMO aren't really needed (e.g. functions for fetching a specific Pulse). At some point in the future, we can clean this namespace up and bring the code in line with the rest of the codebase, but for the time being, it probably makes sense to follow the existing patterns in this namespace rather than further confuse things.

Notifcations are ways to deliver the results of Questions to users without going through the normal Metabase UI. At
the time of this writing, there are two delivery mechanisms for Notifications -- email and Slack notifications;
these destinations are known as 'Channels'. Notifications themselves are futher divied into two categories --
'Pulses', which are sent at specified intervals, and 'Alerts', which are sent when certain conditions are met (such
as a query returning results).

Because 'Pulses' were originally the only type of Notification, this name is still used for the model itself, and in
some of the functions below. To keep things clear try to make sure you use the term 'Notification' for things that
work with either type.

One more thing to keep in mind: this code is pretty old and doesn't follow the code patterns used in the other
Metabase models. There is a plethora of CRUD functions for working with Pulses that IMO aren't really needed (e.g.
functions for fetching a specific Pulse). At some point in the future, we can clean this namespace up and bring the
code in line with the rest of the codebase, but for the time being, it probably makes sense to follow the existing
patterns in this namespace rather than further confuse things.
raw docstring

AlertConditionsclj

Schema for valid values of :alert_condition for Alerts.

Schema for valid values of `:alert_condition` for Alerts.
sourceraw docstring

card->refclj

(card->ref card)

Inputs: [card :- su/Map] Returns: CardRef

Create a card reference from a card or id

Inputs: [card :- su/Map]
Returns: CardRef

Create a card reference from a card or id
sourceraw docstring

CardRefclj

Schema for the map we use to internally represent the fact that a Card is in a Notification and the details about its presence there.

Schema for the map we use to internally represent the fact that a Card is in a Notification and the details about its
presence there.
sourceraw docstring

cardsclj

(cards notification-or-id)

Inputs: [notification-or-id] Returns: [HybridPulseCard]

Return the Cards associated with this notification.

Inputs: [notification-or-id]
Returns: [HybridPulseCard]

Return the Cards associated with this `notification`.
sourceraw docstring

channelsclj

(channels notification-or-id)

Return the PulseChannels associated with this notification.

Return the PulseChannels associated with this `notification`.
sourceraw docstring

CoercibleToCardRefclj

Schema for functions accepting either a HybridPulseCard or CardRef.

Schema for functions accepting either a `HybridPulseCard` or `CardRef`.
sourceraw docstring

create-alert!clj

(create-alert! alert creator-id card-id channels)

Creates a pulse with the correct fields specified for an alert

Creates a pulse with the correct fields specified for an alert
sourceraw docstring

create-pulse!clj

(create-pulse! cards channels kvs)

Inputs: [cards :- [#:s{Keyword s/Any}] channels :- [#:s{Keyword s/Any}] kvs :- {:name su/NonBlankString, :creator_id su/IntGreaterThanZero, (s/optional-key :skip_if_empty) (s/maybe s/Bool), (s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero)}]

Create a new Pulse by inserting it into the database along with all associated pieces of data such as: PulseCards, PulseChannels, and PulseChannelRecipients.

Returns the newly created Pulse, or throws an Exception.

Inputs: [cards :- [#:s{Keyword s/Any}] channels :- [#:s{Keyword s/Any}] kvs :- {:name su/NonBlankString, :creator_id su/IntGreaterThanZero, (s/optional-key :skip_if_empty) (s/maybe s/Bool), (s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero)}]

Create a new Pulse by inserting it into the database along with all associated pieces of data such as:
PulseCards, PulseChannels, and PulseChannelRecipients.

 Returns the newly created Pulse, or throws an Exception.
sourceraw docstring

HybridPulseCardclj

This schema represents the cards that are included in a pulse. This is the data from the PulseCard and some additional information used by the UI to display it from Card. This is a superset of CardRef and is coercible to a CardRef

This schema represents the cards that are included in a pulse. This is the data from the `PulseCard` and some
additional information used by the UI to display it from `Card`. This is a superset of `CardRef` and is coercible to
a `CardRef`
sourceraw docstring

Pulseclj

(Pulse)
(Pulse id)
(Pulse & kvs)

Entity for 'pulse' table; instance of PulseInstance.

Entity for 'pulse' table; instance of PulseInstance.
sourceraw docstring

retrieve-alertclj

(retrieve-alert alert-or-id)

Inputs: [alert-or-id] Returns: (s/maybe PulseInstance)

Fetch a single Alert by its id value, do the standard hydrations, and put it in the standard Alert format.

Inputs: [alert-or-id]
Returns: (s/maybe PulseInstance)

Fetch a single Alert by its `id` value, do the standard hydrations, and put it in the standard `Alert` format.
sourceraw docstring

retrieve-alertsclj

(retrieve-alerts)
(retrieve-alerts {:keys [archived?] :or {archived? false}})

Inputs: ([] [{:keys [archived?], :or {archived? false}}]) Returns: [PulseInstance]

Fetch all Alerts.

Inputs: ([] [{:keys [archived?], :or {archived? false}}])
Returns: [PulseInstance]

Fetch all Alerts.
sourceraw docstring

retrieve-alerts-for-cardsclj

(retrieve-alerts-for-cards & card-ids)

Find all alerts for CARD-IDS, used for admin users

Find all alerts for `CARD-IDS`, used for admin users
sourceraw docstring

retrieve-notificationclj

(retrieve-notification notification-or-id & additional-condtions)

Inputs: [notification-or-id & additional-condtions] Returns: (s/maybe PulseInstance)

Fetch an Alert or Pulse, and do the 'standard' hydrations.

Inputs: [notification-or-id & additional-condtions]
Returns: (s/maybe PulseInstance)

Fetch an Alert or Pulse, and do the 'standard' hydrations.
sourceraw docstring

retrieve-pulseclj

(retrieve-pulse pulse-or-id)

Inputs: [pulse-or-id] Returns: (s/maybe PulseInstance)

Fetch a single Pulse, and hydrate it with a set of 'standard' hydrations; remove Alert coulmns, since this is a Pulse and they will all be unset.

Inputs: [pulse-or-id]
Returns: (s/maybe PulseInstance)

Fetch a single *Pulse*, and hydrate it with a set of 'standard' hydrations; remove Alert coulmns, since this is a
*Pulse* and they will all be unset.
sourceraw docstring

retrieve-pulsesclj

(retrieve-pulses)
(retrieve-pulses {:keys [archived?] :or {archived? false}})

Inputs: ([] [{:keys [archived?], :or {archived? false}}]) Returns: [PulseInstance]

Fetch all Pulses.

Inputs: ([] [{:keys [archived?], :or {archived? false}}])
Returns: [PulseInstance]

Fetch all `Pulses`.
sourceraw docstring

retrieve-user-alerts-for-cardclj

(retrieve-user-alerts-for-card card-id user-id)

Find all alerts for card-id that user-id is set to receive

Find all alerts for `card-id` that `user-id` is set to receive
sourceraw docstring

unsubscribe-from-alert!clj

(unsubscribe-from-alert! alert-id user-id)

Unsubscribe a User with user-id from an Alert with alert-id.

Unsubscribe a User with `user-id` from an Alert with `alert-id`.
sourceraw docstring

update-alert!clj

(update-alert! alert)

Updates the given ALERT and returns it

Updates the given `ALERT` and returns it
sourceraw docstring

update-notification!clj

(update-notification! notification)

Inputs: [notification :- {(s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :skip_if_empty) s/Bool, (s/optional-key :alert_first_only) s/Bool, (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero), (s/optional-key :channels) [su/Map], (s/optional-key :name) su/NonBlankString, (s/optional-key :cards) [CoercibleToCardRef], :id su/IntGreaterThanZero, (s/optional-key :alert_above_goal) s/Bool, (s/optional-key :alert_condition) AlertConditions, (s/optional-key :archived) s/Bool}]

Update the supplied keys in a notification.

Inputs: [notification :- {(s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :skip_if_empty) s/Bool, (s/optional-key :alert_first_only) s/Bool, (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero), (s/optional-key :channels) [su/Map], (s/optional-key :name) su/NonBlankString, (s/optional-key :cards) [CoercibleToCardRef], :id su/IntGreaterThanZero, (s/optional-key :alert_above_goal) s/Bool, (s/optional-key :alert_condition) AlertConditions, (s/optional-key :archived) s/Bool}]

Update the supplied keys in a `notification`.
sourceraw docstring

update-notification-cards!clj

(update-notification-cards! notification-or-id card-refs)

Inputs: [notification-or-id card-refs :- (s/maybe [CardRef])]

Update the PulseCards for a given notification-or-id. card-refs should be a definitive collection of all Cards for the Notification in the desired order. They should have keys like id, include_csv, and include_xls.

  • If a Card ID in card-refs has no corresponding existing PulseCard object, one will be created.
  • If an existing PulseCard has no corresponding ID in CARD-IDs, it will be deleted.
  • All cards will be updated with a position according to their place in the collection of card-ids
Inputs: [notification-or-id card-refs :- (s/maybe [CardRef])]

Update the PulseCards for a given `notification-or-id`.
 `card-refs` should be a definitive collection of *all* Cards for the Notification in the desired order. They should
have keys like `id`, `include_csv`, and `include_xls`.

 *  If a Card ID in `card-refs` has no corresponding existing `PulseCard` object, one will be created.
 *  If an existing `PulseCard` has no corresponding ID in CARD-IDs, it will be deleted.
 *  All cards will be updated with a `position` according to their place in the collection of `card-ids`
sourceraw docstring

update-notification-channels!clj

(update-notification-channels! notification-or-id channels)

Inputs: [notification-or-id channels :- [su/Map]]

Update the PulseChannels for a given notification-or-id. CHANNELS should be a definitive collection of all of the channels for the the pulse.

  • If a channel in the list has no existing PulseChannel object, one will be created.
  • If an existing PulseChannel has no corresponding entry in CHANNELS, it will be deleted.
  • All previously existing channels will be updated with their most recent information.
Inputs: [notification-or-id channels :- [su/Map]]

Update the PulseChannels for a given `notification-or-id`.
 CHANNELS should be a definitive collection of *all* of the channels for the the pulse.

 * If a channel in the list has no existing `PulseChannel` object, one will be created.
 * If an existing `PulseChannel` has no corresponding entry in CHANNELS, it will be deleted.
 * All previously existing channels will be updated with their most recent information.
sourceraw docstring

update-pulse!clj

(update-pulse! pulse)

Inputs: [pulse]

Update an existing Pulse, including all associated data such as: PulseCards, PulseChannels, and PulseChannelRecipients.

Returns the updated Pulse or throws an Exception.

Inputs: [pulse]

Update an existing Pulse, including all associated data such as: PulseCards, PulseChannels, and
PulseChannelRecipients.

Returns the updated Pulse or throws an Exception.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close