Documentation
¶
Overview ¶
Package notification models notifications sent to users.
Index ¶
- Constants
- func FormatSlackTarget(ctx context.Context, target string) (string, error)
- func InsertFailedWebhook(ctx context.Context, n *Notification, sendErr error) error
- func InsertMany(ctx context.Context, items ...Notification) error
- func MarkFailedWebhookRetried(ctx context.Context, notificationID string) (bool, error)
- func RemoveFailedWebhook(ctx context.Context, notificationID string) error
- type FailedWebhook
- type Notification
- func Find(ctx context.Context, id string) (*Notification, error)
- func FindByEventID(ctx context.Context, id string) ([]Notification, error)
- func FindUnprocessed(ctx context.Context) ([]Notification, error)
- func New(eventID, trigger string, subscriber *event.Subscriber, payload any) (*Notification, error)
- func (n *Notification) Composer(ctx context.Context) (message.Composer, error)
- func (n *Notification) MarkError(ctx context.Context, sendErr error) error
- func (n *Notification) MarkSent(ctx context.Context) error
- func (n *Notification) SenderKey() (evergreen.SenderKey, error)
- func (n *Notification) SetBSON(raw mgobson.Raw) error
- func (n *Notification) SetTaskMetadata(ID string, execution int, createdBy string)
- func (d *Notification) UnmarshalBSON(in []byte) error
- type NotificationMetadata
- type NotificationStats
- type SlackPayload
Constants ¶
const (
Collection = "notifications"
)
const (
// FailedWebhookCollection stores webhook notifications that failed to deliver.
FailedWebhookCollection = "failed_webhooks"
)
Variables ¶
This section is empty.
Functions ¶
func FormatSlackTarget ¶
FormatSlackTarget uses the slackMemberId instead of the userName when possible.
func InsertFailedWebhook ¶
func InsertFailedWebhook(ctx context.Context, n *Notification, sendErr error) error
InsertFailedWebhook records a webhook notification that failed to deliver.
func InsertMany ¶
func InsertMany(ctx context.Context, items ...Notification) error
func MarkFailedWebhookRetried ¶
MarkFailedWebhookRetried atomically claims a failed webhook for retry and reports whether this caller claimed it.
Types ¶
type FailedWebhook ¶
type FailedWebhook struct {
NotificationID string `bson:"_id"`
Project string `bson:"project,omitempty"`
Error string `bson:"error"`
FailedAt time.Time `bson:"failed_at"`
RetriedAt time.Time `bson:"retried_at,omitempty"`
}
func FindFailedWebhooks ¶
func FindFailedWebhooks(ctx context.Context, projects []string) ([]FailedWebhook, error)
FindFailedWebhooks returns webhook deliveries that failed and are not claimed by an in-progress retry, up to failedWebhookMaxLimit.
type Notification ¶
type Notification struct {
ID string `bson:"_id"`
Subscriber event.Subscriber `bson:"subscriber"`
Payload any `bson:"payload"`
Project string `bson:"project,omitempty"`
SubscriptionID string `bson:"subscription_id,omitempty"`
SentAt time.Time `bson:"sent_at,omitempty"`
Error string `bson:"error,omitempty"`
Metadata NotificationMetadata `bson:"metadata,omitempty"`
}
func FindByEventID ¶
func FindByEventID(ctx context.Context, id string) ([]Notification, error)
func FindUnprocessed ¶
func FindUnprocessed(ctx context.Context) ([]Notification, error)
func New ¶
func New(eventID, trigger string, subscriber *event.Subscriber, payload any) (*Notification, error)
New returns a new Notification, with a correctly initialised ID
func (*Notification) Composer ¶
Composer builds a grip/message.Composer for the notification. Composer is guaranteed to be non-nil if error is nil, but the composer may not be loggable
func (*Notification) MarkError ¶
func (n *Notification) MarkError(ctx context.Context, sendErr error) error
MarkError marks the notification as sent with the given error.
func (*Notification) MarkSent ¶
func (n *Notification) MarkSent(ctx context.Context) error
MarkSent marks the notification as sent and clears any previous delivery error.
func (*Notification) SenderKey ¶
func (n *Notification) SenderKey() (evergreen.SenderKey, error)
SenderKey returns an evergreen.SenderKey to get a grip sender for this notification from the evergreen environment
func (*Notification) SetTaskMetadata ¶
func (n *Notification) SetTaskMetadata(ID string, execution int, createdBy string)
func (*Notification) UnmarshalBSON ¶
func (d *Notification) UnmarshalBSON(in []byte) error
type NotificationMetadata ¶
type NotificationMetadata struct {
TaskID string `bson:"task_id,omitempty"`
TaskExecution int `bson:"task_execution,omitempty"`
CreatedBy string `bson:"created_by,omitempty"`
// PatchID is the patch whose GitHub statuses a GitHub status notification
// reports on.
PatchID string `bson:"patch_id,omitempty"`
}
type NotificationStats ¶
type NotificationStats struct {
GithubPullRequest int `json:"github_pull_request" bson:"github_pull_request" yaml:"github_pull_request"`
JIRAIssue int `json:"jira_issue" bson:"jira_issue" yaml:"jira_issue"`
JIRAComment int `json:"jira_comment" bson:"jira_comment" yaml:"jira_comment"`
EvergreenWebhook int `json:"evergreen_webhook" bson:"evergreen_webhook" yaml:"evergreen_webhook"`
Email int `json:"email" bson:"email" yaml:"email"`
Slack int `json:"slack" bson:"slack" yaml:"slack"`
GithubCheck int `json:"github_check" bson:"github_check" yaml:"github_check"`
GithubMerge int `json:"github_merge" bson:"github_merge" yaml:"github_merge"`
}
func CollectUnsentNotificationStats ¶
func CollectUnsentNotificationStats(ctx context.Context) (*NotificationStats, error)
type SlackPayload ¶
type SlackPayload struct {
Body string `bson:"body"`
Attachments []message.SlackAttachment `bson:"attachments"`
}