mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: implement thin vertical slice of system-generated notifications (#13537)
This commit is contained in:
35
coderd/notifications/spec.go
Normal file
35
coderd/notifications/spec.go
Normal file
@ -0,0 +1,35 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/notifications/dispatch"
|
||||
"github.com/coder/coder/v2/coderd/notifications/types"
|
||||
)
|
||||
|
||||
// Store defines the API between the notifications system and the storage.
|
||||
// This abstraction is in place so that we can intercept the direct database interactions, or (later) swap out these calls
|
||||
// with dRPC calls should we want to split the notifiers out into their own component for high availability/throughput.
|
||||
// TODO: don't use database types here
|
||||
type Store interface {
|
||||
AcquireNotificationMessages(ctx context.Context, params database.AcquireNotificationMessagesParams) ([]database.AcquireNotificationMessagesRow, error)
|
||||
BulkMarkNotificationMessagesSent(ctx context.Context, arg database.BulkMarkNotificationMessagesSentParams) (int64, error)
|
||||
BulkMarkNotificationMessagesFailed(ctx context.Context, arg database.BulkMarkNotificationMessagesFailedParams) (int64, error)
|
||||
EnqueueNotificationMessage(ctx context.Context, arg database.EnqueueNotificationMessageParams) (database.NotificationMessage, error)
|
||||
FetchNewMessageMetadata(ctx context.Context, arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow, error)
|
||||
GetNotificationMessagesByStatus(ctx context.Context, arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage, error)
|
||||
}
|
||||
|
||||
// Handler is responsible for preparing and delivering a notification by a given method.
|
||||
type Handler interface {
|
||||
// Dispatcher constructs a DeliveryFunc to be used for delivering a notification via the chosen method.
|
||||
Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error)
|
||||
}
|
||||
|
||||
// Enqueuer enqueues a new notification message in the store and returns its ID, should it enqueue without failure.
|
||||
type Enqueuer interface {
|
||||
Enqueue(ctx context.Context, userID, templateID uuid.UUID, labels map[string]string, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error)
|
||||
}
|
Reference in New Issue
Block a user