Skip to main content

Module delivery

Module delivery 

Source
Expand description

Delivery of notifications by e-mail and to Mattermost.

The notifications table is the outbox: a notification is created with email_state / chat_state = pending when the user wants that channel. A background task (spawn) sends the pending ones every few seconds:

  • E-mail via SMTP (lettre, MIT) when TEAMCRAFT_SMTP_URL and TEAMCRAFT_MAIL_FROM are set; plain text with a link to the object and to the notification settings.
  • Mattermost as a direct message from a bot account through the REST API (crate::mattermost, TEAMCRAFT_MATTERMOST_URL + …_BOT_TOKEN); never a post in a channel. An unknown or deactivated user fails at once with a reason the user sees. Deprecated: an incoming webhook (TEAMCRAFT_MATTERMOST_WEBHOOK): a post in the webhook’s channel that @-mentions the user, or a direct message (TEAMCRAFT_MATTERMOST_DIRECT=true). The Mattermost user is the TeamCraft username unless the user set another one.

Without configuration the pending rows are marked skipped. A failed delivery is retried on the next runs and marked failed after MAX_ATTEMPTS. One TeamCraft instance delivers (no row locking).

A run serves PARALLEL_RECIPIENTS recipients at the same time; the notifications of one recipient go out one after the other, in the order they were queued, e-mail and chat of a notification side by side. A mail server that answers slowly (the SMTP timeout is 20 s) holds up the recipient it is serving, not the whole run and not the chat messages.

Structs§

Delivery
The configured channels.
Report
What one run delivered.

Constants§

MAX_ATTEMPTS
Delivery attempts per channel before a notification is marked failed.
PARALLEL_RECIPIENTS
Recipients served at the same time, i.e. the connections one run opens to the mail server at most. Hosted mail services limit the simultaneous connections of one sender to a handful (three is common), so this stays small: enough that one slow delivery does not hold up the others.

Traits§

ChatSender
Posts to Mattermost (an incoming webhook in production).
MailSender
Sends one e-mail (SMTP in production, a recorder in tests).

Functions§

chat_payload
Mattermost webhook payload: a mention in the channel or a direct message.
chat_text
What a chat message may show. A notification about a restricted project group posted into a shared channel (not a direct message) shows only a generic text and the link; everybody in the channel could read it.
email_text
Plain-text body of a notification e-mail.
generic_text
Title and body of a notification whose group switched notification_content off: nothing about the object, only that there is something and (added by the sender) the link.
spawn
Starts the background delivery (does nothing if no channel is configured, apart from marking the pending notifications as skipped).

Type Aliases§

BoxFuture